|
|
|
รบกวนสอบถามเรื่องการเปิดไฟล์ excel เพื่อแก้ไขข้อมูลด้วย php ไม่ทราบว่ามีวิธีอย่างไรบ้างครับ |
|
|
|
|
|
|
|
Code (PHP)
$file = fopen('UpdateDB/DB.txt',"r");
$data = fgets($file);
fclose($file);
ในส่วนขอการเรียกมาอ่าน ก็ประมาณนี้ครับ นี่เป็น ตัอย่า ไฟล์ txt ตรง .txt ก็เปลี่ยนเป้น .ของ excel เอานะครับ
|
|
|
|
|
Date :
2011-06-27 08:38:47 |
By :
taza678 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
โค๊ดที่ผมใช้เป็นแบบนี้ครับ ต้องปรับเปลี่ยนตรงไหนครับ รบกวนขอคำแนะนำด้วยน่ะครับ ขอบคุณครับ หรือผมต้องไปเซ็ตอะไรก่อนหรือเปล่าก่อนใช้ app ของ excel ครับ
Code (PHP)
<?
//*** Get Document Path ***//
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
//*** Excel Document Root ***//
$strFileName = "b1.xls";
//*** Connect to Excel.Application ***//
$xlApp = new COM("Excel.Application");
$xlBook = $xlApp->Workbooks->Add();
$xlSheet1 = $xlBook->Worksheets(1);
$xlApp->Application->Visible = False;
//*** Create Sheet 1 ***//
$xlBook->Worksheets(1)->Name = "My Sheet1";
$xlBook->Worksheets(1)->Select;
//*** Width & Height (A1:A1) ***//
$xlApp->ActiveSheet->Range("A1:A1")->ColumnWidth = 40.0;
$xlApp->ActiveSheet->Range("A1:A1")->RowHeight = 25.0;
//*** Write text to Row 1 Column 1 ***//
$xlApp->ActiveSheet->Cells(1,1)->Value = "ThaiCreate.Com ";
$xlApp->ActiveSheet->Cells(1,1)->Font->Name = "Tahoma";
$xlApp->ActiveSheet->Cells(1,1)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(1,1)->VerticalAlignment = -4108; //*** Center Rows ***//
$xlApp->ActiveSheet->Cells(1,1)->HorizontalAlignment = -4108; //*** Center Column ***//
$xlApp->ActiveSheet->Cells(1,1)->Font->Size = 12;
//*** Write text to Row 1 Column 2 ***//
$xlApp->ActiveSheet->Cells(1,2)->Value = "Mr.Weerachai Nukitram ";
$xlApp->ActiveSheet->Cells(1,2)->Font->Name = "Tahoma";
$xlApp->ActiveSheet->Cells(1,2)->Font->Size = 20;
//*** Width & Height (A2:A2) ***//
$xlApp->ActiveSheet->Range("A2:A2")->BORDERS->Weight = 1; //*** Border ***//
//*** Write text to Row 1 Column 2 ***//
$xlApp->ActiveSheet->Cells(2,1)->Value = "I Love ThaiCreate.Com ";
$xlApp->ActiveSheet->Cells(2,1)->Font->Name = "Tahoma";
$xlApp->ActiveSheet->Cells(2,1)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(2,1)->HorizontalAlignment = 4;
//*** Width & Height (A3:D3) ***//
$xlApp->ActiveSheet->Range("A3:D3")->BORDERS->Color = 44; //*** Border Color ***//
$xlApp->ActiveSheet->Range("A3:D3")->BORDERS->Weight = 1; //*** Border ***//
$xlApp->ActiveSheet->Range("A3:D3")->MergeCells = True; //*** Merge Cells ***//
//*** Write text to Row 1 Column 2 ***//
$xlApp->ActiveSheet->Cells(3,1)->Value = "I Love My Live";
$xlApp->ActiveSheet->Cells(3,1)->Font->Name = "Tahoma";
$xlApp->ActiveSheet->Cells(3,1)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(3,1)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,1)->Interior->ColorIndex = 44; //*** Background Color ***//
//*** Write text to Row 4 Column 5 ***//
$xlApp->ActiveSheet->Cells(4,5)->Value = "My Live";
$xlApp->ActiveSheet->Cells(4,5)->Font->Name = "Tahoma";
$xlApp->ActiveSheet->Cells(4,5)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(4,5)->Font->Italic = True;
$xlApp->ActiveSheet->Cells(4,5)->Font->ColorIndex = 4;
$xlApp->ActiveSheet->Cells(4,5)->EntireColumn->AutoFit; //*** AutoFit Column ***//
@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;
?>
Excel Created <a href="<?=$strFileName?>">Click here</a> to Download.
|
|
|
|
|
Date :
2011-06-27 10:31:38 |
By :
ratthasit |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
windows 7 ms-office 2007 ครับ
|
|
|
|
|
Date :
2011-06-28 11:09:22 |
By :
ratthasit |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|