Does anyone know if that can be done?
Jim
You could do this if you have MS Excel installed on the target machine,
using PHP support for COM.
<?php
$strSheetName = 'Sheet1'
$strCellName = 'A1';
$objXLApp = new COM( "excel.application" ) or die( "unable to start
MSExcel" );
$objXLApp->Workbooks->Open( "c:\\temp\\test.xls" );
$objXLSheet = $objXLApp->ActiveWorkBook->WorkSheets( $strSheetName );
$objXLCell = $objXLSheet->Range( $strCellName );
print "Cell $strCellName in $strSheetName: \"" . $objXLCell->Value() .
"\"\n";
// must do all of these to release resources correctly...
unset( $objXLCell );
unset( $objXLSheet );
$objXLApp->ActiveWorkBook->Close();
$objXLApp->Quit();
unset( $objXLApp );
?>
---
Steve
Exactly what I was looking for. I'll try it later today.
I tried it and it works great. Can you point me to any examples that get the number of rows & columns and loops through these?
Or, where can I find documentation on these (php related) functions?
Jim
In this example PHP provides only the creation of the object $objXLApp
using the COM support class. See
http://www.php.net/manual/en/class.com.php
Everything after that is passed through to the COM object, so they are
native MS Excel methods and properties. Slightly off-topic: you'll find
documentation for these either from within MS Excel (Tools/Macros/VB
Editor: Help/MS VB Help) or via the usual MS support sites.
---
Steve
You have received some good answers to this, but I would just like to point
out a terminology problem with your question.
PHP does not "read" MySQL files at all. No applications do. What PHP
knows how to do is make requests of a MySQL server. It is the MySQL
database server that reads and writes the MySQL files.
The Excel solutions you have been given are the same. PHP, in that case,
is NOT reading .xls files directly, as your subject line asked. Instead,
it is launching a copy of Excel itself, and making requests of it as if it
were an "Excel server".
It seems nitpicky, but it is an important difference.
--
- Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.