I am having some issue of saving data into excel. Here is my source code:
$path_name = 'F:/temp.xls';
$strFileName = 'temp.xls';
$xlSheet1 = new COM("Excel.Sheet");
$xlApp = new COM("Excel.Application");
echo "Application name: ".$xlSheet1->Application->value."<br/>" ;
echo "Loaded version: ".$xlSheet1->Application->version."<br/>";
$xlBook = $xlApp->Workbooks->Add();
echo "Workbook Opened <br/>";
$xlSheet1->Application->Visible = 1;
//*** Create Sheet 1 ***//
$Sheet = $xlBook->Worksheets(1);
echo "Select a sheet <br/>";
$xlBook->Worksheets(1)->Activate;
echo "Activate sheet <br/>";
$Sheet->Name = $xlTabName;
echo "Name sheet to ".$xlTabName."<br/>";
echo "Insert column headers <br/>";
//*** Header ***//
$cell = $Sheet->Cells(1,1)->Value = "ITEM";
$cell = $Sheet->Cells(1,2)->Value = "PRICE2";
$cell = $Sheet->Cells(1,3)->Value = "AQTY";
$cell = $Sheet->Cells(1,4)->Value = "QTYORD";
echo "Insert data into columns <br/>";
$intRows = 2;
while($objResult = mysqli_fetch_row($objQuery))
{
$cell = $Sheet->Cells($intRows,1)->Value = $objResult[0];
$cell = $Sheet->Cells($intRows,2)->Value = $objResult[1];
$cell = $Sheet->Cells($intRows,3)->Value = $objResult[2];
$cell = $Sheet->Cells($intRows,4)->Value = $objResult[3];
//*** Detail ***//
//$xlApp->$Sheet->Cells($intRows,1)->Value = $objResult[0];
//$xlApp->$Sheet->Cells($intRows,2)->Value = $objResult[1];
//$xlApp->$Sheet->Cells($intRows,3)->Value = $objResult[2];
//$xlApp->ActiveSheet->Cells($intRows,4)->Value = $objResult["disc"];
//$xlApp->ActiveSheet->Cells($intRows,5)->Value = $objResult["discls"];
//$xlApp->$Sheet->Cells($intRows,4)->Value = $objResult[3];
$intRows++;
}
if(file_exists($path_name))
{
unlink($file_name);
echo "Remove existing File";
}
$xlBook->Save($path_name); //*** Save to Path ***//
echo "File is saved <br/>";
//*** Close & Quit ***//
$xlApp->Quit();
$xlSheet1->Quit();
unset($xlApp);
unset($xlSheet);