How to use PHP & Delete Sheet in excel (Excel.Application) The Learn / tutorial php programming how to using PHP delete sheet in excel.
ShotDev Focus:
- PHP & Delete sheet in excel.
Example
php_delete_sheet.php
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<?
//*** 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();
$xlSheet1 = $xlBook->Worksheets(1);
//*** Sheet 1 ***//
$xlSheet1->Name = "My Sheet1";
//*** Write text to Row 1 Column 1 ***//
$xlApp->ActiveSheet->Cells(1,1)->Value = "ShotDev.Com";
//*** Write text to Row 1 Column 2 ***//
$xlApp->ActiveSheet->Cells(1,2)->Value = "Mr.Weerachai Nukitram";
//*** Delete Sheet 2 ***//
$xlBook->Worksheets(2)->Select;
$xlBook->Worksheets(2)->Delete;
//*** Delete Sheet 3 ***//
$xlBook->Worksheets(2)->Select;
$xlBook->Worksheets(2)->Delete;
$xlApp->Application->Visible = False;
@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.
</body>
</html>
Create a php file and save to path root-path/myphp/
Run
http://localhost/myphp/php_delete_sheet.php
Screenshot


