 |
คืิอต้องกานจะ export หน้าเวบที่ดืงข้อมูลจาก table มาโช..สามาดเปีดเป็น excel ได้ทำไงคะ |
|
 |
|
|
 |
 |
|
ต้องกานจะทำไห้หน้าเวบที่ยู่ไน localhost ,มี link ข้อความว่า open to excel แล้วถ้ากด link แล้วไห้เปีดหน้า excel ขี้นมา แต่หน้าเวบ localhost ยังยู่เหมือนเดีมนะ แนะนำแด่จ๋า
เราทำแบบนี้มันไม่ออก
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Datepicker</title>
</head>
<body
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM shortcode";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
//*** Get Document Path ***//
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
//*** Excel Document Root ***//
$strFileName = "MyXls/MyExcel.xls";
//*** Connect to Excel.Application ***//
$xlApp = new COM("Excel.Application");
$xlBook = $xlApp->Workbooks->Add();
//*** Create Sheet 1 ***//
$xlBook->Worksheets(1)->Name = "My Shortcode";
$xlBook->Worksheets(1)->Select;
//*** Header ***//
$xlApp->ActiveSheet->Cells(1,1)->Value = "No";
$xlApp->ActiveSheet->Cells(1,2)->Value = "Shortcode";
$xlApp->ActiveSheet->Cells(1,3)->Value = "ຊື່ບໍລິສັດ";
$xlApp->ActiveSheet->Cells(1,4)->Value = "ເລີ່ມຕົ້ນ";
$xlApp->ActiveSheet->Cells(1,5)->Value = "ໝົດອາຍຸ";
$xlApp->ActiveSheet->Cells(1,6)->Value = "ສັນຍາເລກທີ";
$xlApp->ActiveSheet->Cells(1,7)->Value = "ລາຄາ/sms";
$xlApp->ActiveSheet->Cells(1,8)->Value = "ອາກອນ";
$xlApp->ActiveSheet->Cells(1,9)->Value = "ສ່ວນແບ່ງ ETL";
$xlApp->ActiveSheet->Cells(1,10)->Value = "ສ່ວນແບ່ງ Partner";
$xlApp->ActiveSheet->Cells(1,11)->Value = "ເບີຕິດຕໍ່";
$xlApp->ActiveSheet->Cells(1,12)->Value = "ໝາຍເຫດ";
//***********//
$intRows = 2;
while($objResult = mysql_fetch_array($objQuery))
{
//*** Detail ***//
$xlApp->ActiveSheet->Cells($intRows,1)->Value = $objResult["ShortcodeName"];
$xlApp->ActiveSheet->Cells($intRows,2)->Value = $objResult["Company"];
$xlApp->ActiveSheet->Cells($intRows,3)->Value = $objResult["Effect_time"];
$xlApp->ActiveSheet->Cells($intRows,4)->Value = $objResult["Expire_time"];
$xlApp->ActiveSheet->Cells($intRows,5)->Value = $objResult["Reference"];
$xlApp->ActiveSheet->Cells($intRows,6)->Value = $objResult["Price"];
$xlApp->ActiveSheet->Cells($intRows,7)->Value = $objResult["Tax"];
$xlApp->ActiveSheet->Cells($intRows,8)->Value = $objResult["Share_ETL"];
$xlApp->ActiveSheet->Cells($intRows,9)->Value = $objResult["Share_partner"];
$xlApp->ActiveSheet->Cells($intRows,10)->Value = $objResult["Tel"];
$xlApp->ActiveSheet->Cells($intRows,11)->Value = $objResult["Note"];
$intRows++;
}
@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;
}
mysql_close($objConnect);
?>
Excel Created <a href="<?=$strFileName?>">Click here</a> to Download.
</body>
</html>
มัน error ว่า
Code
Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft Office Excel<br/><b>Description:</b> Microsoft Office Excel cannot access the file 'C:\AppServ\www\MyXls\3EA65000'. There are several possible reasons: � The file name or path does not exist. � The file is being used by another program. � The workbook you are trying to save has the same name as a currently open workbook.' in C:\AppServ\www\win2.php:64 Stack trace: #0 C:\AppServ\www\win2.php(64): variant->SaveAs('C:\AppServ\www/...') #1 {main} thrown in C:\AppServ\www\win2.php on line 64
Tag : PHP, MySQL
|
|
 |
 |
 |
 |
Date :
2012-06-19 11:16:50 |
By :
Cat |
View :
1317 |
Reply :
8 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ่าว ไม่ใช่ต้องการ Export ข้อมูลออกมาเป็น Excel หรอกเหรอ
|
 |
 |
 |
 |
Date :
2012-06-19 17:10:37 |
By :
บังเอิญผ่านมาเห็น |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
น้องกะทำลิงค์ไปที่ไฟล์ gen excel ครับ ส่งค่าที่ต้้องการไป แล้ว gen ตอนนั้นมันกะจะดาวน์โหลดให้ครับ
|
 |
 |
 |
 |
Date :
2012-06-19 17:13:23 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช่ครับต้องทำลิ้งค์ไปอีกหน้านึงเพราะถ้าเรา echo ออกมาแล้วมันจะ gen ไฟล์ออกมาไม่ได้ครับ(เท่าที่ประสบมากับตัวครับ)
|
 |
 |
 |
 |
Date :
2012-06-19 17:29:55 |
By :
deer |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|