|
|
|
ช่วยหน่อยครับ ผมใช้ PHPExcel Report ถ้าเป็นตัวเลข Number แล้วขึ้ั้นต้นด้วยเลข 0 เลข 0 จะถูกตัดออก |
|
|
|
|
|
|
|
Code (PHP)
session_start();
/**
* PHPExcel
*
* Copyright (C) 2006 - 2011 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.6, 2011-02-27
*/
/** Error reporting */
error_reporting(E_ALL);
date_default_timezone_set('Europe/London');
/** PHPExcel */
require_once '../Classes/PHPExcel.php';
// Create new PHPExcel object
echo date('H:i:s') . " Create new PHPExcel object\n";
$objPHPExcel = new PHPExcel();
// Set properties
echo date('H:i:s') . " Set properties\n";
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document")
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
->setKeywords("office 2007 openxml php")
->setCategory("Test result file");
// Add some data
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'NO.')
->setCellValue('B1', 'NAME')
->setCellValue('C1', 'LOCATION')
->setCellValue('D1', 'TYPE')
->setCellValue('E1', 'ASSET')
->setCellValue('F1', 'YY')
->setCellValue('G1', 'CPU')
->setCellValue('H1', 'MEMORY')
->setCellValue('I1', 'MAINBORD')
->setCellValue('J1', 'HDD')
->setCellValue('K1', 'MONITOR')
->setCellValue('L1', 'MONITOR_ASSET')
->setCellValue('M1', 'LICEN')
->setCellValue('N1', 'LICENTYPE')
->setCellValue('O1', 'OPERATION SYSTEM')
->setCellValue('P1', 'OFFICE')
->setCellValue('Q1', 'ANIVRUS')
->setCellValue('R1', 'SOFT PRO')
->setCellValue('S1', 'MYDREAM')
->setCellValue('T1', 'IP')
->setCellValue('U1', 'MACIP');
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("computers");
// Write data from MySQL result
$KeyWord1=$_GET['KeyWord1'];
$Search=$_GET['Search'];
$Type=$_SESSION['Type'];
if(!empty($Search)){
$strSQL = "SELECT * FROM coms WHERE ";
$strSQL.="" .$Search." LIKE '%".$KeyWord1."%' ";
mysql_query("SET NAMES UTF8");
}elseif(!empty($Type)){
$strSQL = "SELECT * FROM coms WHERE ";
$strSQL .= " type1 = '".$_SESSION['Type']."'";
mysql_query("SET NAMES UTF8");
}else{
$strSQL = "SELECT * FROM coms ";
mysql_query("SET NAMES UTF8");
}
echo $strSQL;
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
$i = 2;
while($objResult = mysql_fetch_array($objQuery))
{
$strSQL1 = "SELECT * FROM monitor WHERE mo_id='".$objResult['mo_id']."'";
mysql_query("SET NAMES UTF8");
$objQuery1 = mysql_query($strSQL1);
$objResult1 = mysql_fetch_array($objQuery1);
$objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $i-1);
$objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $objResult["com_name"]);
$objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $objResult["dept"]);
$objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $objResult["type1"]);
$objPHPExcel->getActiveSheet()->setCellValue('E' . $i, $objResult['com_id']);
$objPHPExcel->getActiveSheet()->setCellValue('F' . $i, $objResult["startdate"]);
$objPHPExcel->getActiveSheet()->setCellValue('G' . $i, $objResult["cpu"]);
$objPHPExcel->getActiveSheet()->setCellValue('H' . $i, $objResult["ram"]);
$objPHPExcel->getActiveSheet()->setCellValue('I' . $i, $objResult["mainboard"]);
$objPHPExcel->getActiveSheet()->setCellValue('J' . $i, $objResult["harddisk"]);
$objPHPExcel->getActiveSheet()->setCellValue('K' . $i, $objResult1["brand"]." ".$objResult1["model"]);
$objPHPExcel->getActiveSheet()->setCellValue('L' . $i, $objResult1['monitor_id']);
$objPHPExcel->getActiveSheet()->setCellValue('M' . $i, $objResult["licenseos"]);
$objPHPExcel->getActiveSheet()->setCellValue('N' . $i, $objResult["remark"]);
$objPHPExcel->getActiveSheet()->setCellValue('O' . $i, $objResult["os"]);
$objPHPExcel->getActiveSheet()->setCellValue('P' . $i, $objResult["office"]);
$objPHPExcel->getActiveSheet()->setCellValue('Q' . $i, $objResult["antivirus"]);
$objPHPExcel->getActiveSheet()->setCellValue('R' . $i, $objResult["softpro"]);
$objPHPExcel->getActiveSheet()->setCellValue('S' . $i, $objResult["Mydream"]);
$objPHPExcel->getActiveSheet()->setCellValue('T' . $i, $objResult["ip"]);
$objPHPExcel->getActiveSheet()->setCellValue('U' . $i, $objResult["macaddress"]);
$i++;
}
mysql_close($objConnect);
// Rename sheet
echo date('H:i:s') . " Rename sheet\n";
$objPHPExcel->getActiveSheet()->setTitle('My data');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Save Excel 2007 file
echo date('H:i:s') . " Write to Excel2007 format\n";
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$strFileName = "myData.xlsx";
$objWriter->save($strFileName);
// Echo memory peak usage
echo date('H:i:s') . " Peak memory usage: " .(memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n";
// Echo done
echo date('H:i:s') . " Done writing file.\r\n";
Tag : PHP
|
|
|
|
|
|
Date :
2014-10-27 08:51:37 |
By :
raksaksaethao |
View :
1213 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
สามารถใส่ ' (single quote) ข้างหน้าครับ หรือไม่กำหนด Format ของ Cell ให้เป็น String หรือ Text
Code (PHP)
$this->workbook->getActiveSheet()->getStyle($cell)->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_TEXT );
|
|
|
|
|
Date :
2014-10-27 09:13:47 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แทรกตรงไหนครับ
|
|
|
|
|
Date :
2014-10-27 09:26:35 |
By :
raksaksaethao |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$objPHPExcel->getActiveSheet()->setCellValue('B' . $i, "'".$objResult1["com_name"]);
|
|
|
|
|
Date :
2014-10-27 09:59:03 |
By :
armdbz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Fatal error: Using $this when not in object context in C:\AppServ\www\computer\PHPExcel\Examples\02simple.php on line 115
ขึ้นแบบนี้
|
|
|
|
|
Date :
2014-10-27 10:03:03 |
By :
raksaksaethao |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|