export chart graph แบบ excel บน windows 7 แล้ว มีปัญหาครับ
ใช้ phpexcel เอานะครับ ผมก็ติดปัญหา เลยใช้ตัวนี้แทน code ข้างล่างนะครับ
Code (PHP)
<html>
<head>
<title>Export All Machine (sever ไม่ต้องเป็น windows)</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<?
// อย่าลืม load phpexcel มาเก็บใน path ที่ถูกต้องนะครับ
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
$xlEdgeLeft = 7;
$xlEdgeTop = 8;
$xlEdgeBottom = 9;
$xlEdgeRight = 10;
//*** Excel Open Document ***//
//*** Excel Document for savefile***//
$unique= date("Y_m_d_H_i_s");
$strFileName = $unique."_savecontact.xls";
/** Error reporting */
error_reporting(E_ALL);
/** PHPExcel */
require_once 'phpexcel/Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
// Set fonts
$objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setName('tahoma');
$objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setSize(10);
// Set column widths
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(22);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(52);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
// Set alignments
$objPHPExcel->getActiveSheet()->getStyle()->getAlignment('A')->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
$objPHPExcel->getActiveSheet()->getStyle()->getAlignment('B')->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$objPHPExcel->getActiveSheet()->getStyle()->getAlignment('C')->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
$objPHPExcel->getActiveSheet()->getStyle()->getAlignment('D')->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$objPHPExcel->getProperties()->setCreator("www.ideafunction.com");
$objPHPExcel->getProperties()->setLastModifiedBy("www.ideafunction.com");
$objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document");
$objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document");
$objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.");
$objReader = PHPExcel_IOFactory::createReader('Excel5');
$objPHPExcel = $objReader->load("excelfile.xls");
// Rename sheet
$objPHPExcel->getActiveSheet()->setTitle('Simple');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
$objConnect = mysql_connect("localhost","user","password") or die("Error Connect to Database");
$objDB = mysql_select_db("you'r database");
mysql_query("SET NAMES UTF8");
// Sql
$strSQL = "SELECT from where";
$objQuery= mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysql_fetch_array($objQuery);
//** get data row1 **//
// set begin row
$i=2;
while($objResult = mysql_fetch_array($objQuery))
{
// insert row เริ่มที่ 0 เป็น column 1 นะครับ
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $i, $variable);
//$xlApp->ActiveSheet->Cells($i,2)->Value = $objResult["lotno"];
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $i, $variable);
// ขึ้นแถวใหม่
$i=$i+1;
}
mysql_close($objConnect);
// Save file
$objPHPExcel = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objPHPExcel->save($strPath."/".$strFileName);
echo "Process Complete<br/>";
echo "<a href=\" $strFileName\">Click For Open And Save File</a>"
?>
</body>
</html>
Date :
2011-12-18 17:06:52
By :
tumsupercm
Load balance : Server 03