note 40696 deleted from class.com by cmb

From: Date: Tue, 05 Nov 2019 09:16:27 +0000
Subject: note 40696 deleted from class.com by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212895@lists.php.net to get a copy of this message
Note Submitter: flintjt at hotmail dot com ---- I have searched for ways to open and read an excel document and I found some information which I thought that I would document. Information on the object model to help with programming COM objects can be found in your MS Office help files, search for VBA*.chm. Also, here is a script that I used to pull a cell from each worksheet, complete w/ variable for pathnames & worksheets. This script also closes excel completely. The coding might be dirty, but it gets the job done. --------copy from here----------- <pre> <?PHP $filename = "c:/spreadhseet/test.xls"; $sheet1 = 1; $sheet2 = "sheet2"; $excel_app = new COM("Excel.application") or Die ("Did not connect"); print "Application name: {$excel_app->Application->value}\n" ; print "Loaded version: {$excel_app->Application->version}\n"; $Workbook = $excel_app->Workbooks->Open("$filename") or Die("Did not open $filename $Workbook"); $Worksheet = $Workbook->Worksheets($sheet1); $Worksheet->activate; $excel_cell = $Worksheet->Range("C4"); $excel_cell->activate; $excel_result = $excel_cell->value; print "$excel_result\n"; $Worksheet = $Workbook->Worksheets($sheet2); $Worksheet->activate; $excel_cell = $Worksheet->Range("C4"); $excel_cell->activate; $excel_result = $excel_cell->value; print "$excel_result\n"; #To close all instances of excel: $Workbook->Close; unset($Worksheet); unset($Workbook); $excel_app->Workbooks->Close(); $excel_app->Quit(); unset($excel_app); ?> </pre> ----------------------------------

« previous php.notes (#212895) next »