|
|
|
php to excel error ไม่สามารถเรียกคุณสมบัติ SaveAs ของคลาส Workbook ได้ |
|
|
|
|
|
|
|
มัน error บรรทัดนี้ครับ $xlBook->SaveAs($strPath."/".$strFileName);
ตอนแรกยังได้อยู่ แต่พอย้ายเครื่องกลับไม่ได้ซะงั้น เช็คสิทธิแล้วก็ไม่น่าจะมีอะไร แก้ไขยังไงครับ
Code (PHP)
<?
include "config.php";
$periodget = $_POST["txtperiod"];
$datenowex = explode("-", date('Y-m-d'));
$datenowexday = $datenowex[2];
$datenowexmonth = $datenowex[1];
$datenowexyear = $datenowex[0]+543;
$datenowok = $datenowexyear.'-'.$datenowexmonth.'-'.$datenowexday;
$datewant = date('Y-m-d', strtotime("-$periodget months"));
$datewantex = explode("-", $datewant);
$datewantexday = $datewantex[2];
$datewantexmonth = $datewantex[1];
$datewantexyear = $datewantex[0]+543;
$datewantok = $datewantexyear.'-'.$datewantexmonth.'-'.$datewantexday;
//echo $datenowok.' '.$datewantok;
date_default_timezone_set('Asia/Bangkok');
$sql="SELECT * FROM member
WHERE memname<>'' and memaddno<>'' and memtourlast BETWEEN '$datewantok' and '$datenowok' order by memlet asc";
$query=mysql_query($sql);
$num=mysql_num_rows($query);
if($num<>0){
//*** Get Document Path ***//
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
//*** Excel Document Root ***//
$strFileName = "Myxls/รายชื่อสมาชิกชมรมกอล์ฟสิงห์ระยอง ".date("Y-m-d").".xls";
//echo $strFileName;
//*** Connect to Excel.Application ***//
$xlApp = new COM("Excel.Application");
$xlBook = $xlApp->Workbooks->Add();
//*** Create Sheet 1 ***//
$xlBook->Worksheets(1)->Name = "Listmember";
$xlBook->Worksheets(1)->Select;
//*** Header ***//
$xlApp->ActiveSheet->Cells(1,1)->Value = "รหัส";
$xlApp->ActiveSheet->Cells(1,2)->Value = "ชื่อสมาชิก";
$xlApp->ActiveSheet->Cells(1,3)->Value = "นามสกุล";
$xlApp->ActiveSheet->Cells(1,4)->Value = "";
$xlApp->ActiveSheet->Cells(1,5)->Value = "รหัสไปรษณีย์";
$xlApp->ActiveSheet->Cells(1,6)->Value = "เบอร์ติดต่อ";
//***********//
$intRows = 2;
while($rs=mysql_fetch_array($query)){
//echo"<tr>";
$memlet = $rs[memlet];
$memnum = $rs[memnum];
$memname = $rs[memname];
$memlname = $rs[memlname];
$memaddno = $rs[memaddno];
$memroad = $rs[memroad];
$memtum = $rs[memtum];
$memaum = $rs[memaum];
$memprovince = $rs[memprovince];
$mempost = $rs[mempost];
$memaddfull = $memaddno.' ถ.'.$memroad.' ต.'.$memtum.' อ.'.$memaum.' จ.'.$memprovince;
$memtel = $rs[memtel];
//*** Detail ***//
$xlApp->ActiveSheet->Cells($intRows,1)->Value = $memlet;
$xlApp->ActiveSheet->Cells($intRows,2)->Value = $memnum.' '.$memname;
$xlApp->ActiveSheet->Cells($intRows,3)->Value = $memlname;
$xlApp->ActiveSheet->Cells($intRows,4)->Value = $memaddfull;
$xlApp->ActiveSheet->Cells($intRows,5)->Value = $mempost;
$xlApp->ActiveSheet->Cells($intRows,6)->Value = $memtel;
$intRows++;
?>
<!-- <td align='center' width='100'><font style='font-size: 18px;'><?echo $memlet;?></td>
<td><font style='font-size: 14px;'><?echo $memnum.' '.$memname;?></td>
<td><font style='font-size: 14px;'><?echo $memlname;?></td>
<td><font style='font-size: 14px;'><?echo $memaddfull;?></td>
<td align='center'><font style='font-size: 14px;'><?echo $mempost;?></td>
<td><font style='font-size: 14px;'><?echo $memtel;?></td> -->
<?
}
@unlink($strFileName); //*** Delete old files ***//
$xlBook->SaveAs($strPath."/".$strFileName); //*** Save to Path ***//
//$xlBook->SaveAs(realpath($strFileName)); //*** Save to Path ***//
//*** Close & Quit ***//
$xlApp->Application->Quit();
$xlApp = null;
$xlBook = null;
$xlSheet1 = null;
//echo"</table>";
}
mysql_close();
?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2015-10-12 21:22:10 |
By :
chanonman2 |
View :
934 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เปลี่ยนไปใช้ PHPExcel แทนนะครับ สำรหับตัวนี้ต้อง Config หลายส่วนครับ ทั้ง Permission ของ DCOM ซึ่งจะใช้งานยากพอควรครับ
|
|
|
|
|
Date :
2015-10-13 11:05:48 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|