I'd like to be able to read a microsoft spreadsheet with php. I know that php can read mysql, so I was thinking that maybe it could read excel spreadsheets as well.
James Johnson wrote:[color=blue]
> I'd like to be able to read a microsoft spreadsheet with php. I know[/color]
that php can read mysql, so I was thinking that maybe it could read
excel spreadsheets as well.[color=blue]
>
> Does anyone know if that can be done?
>
> Jim[/color]
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.applicat ion" ) or die( "unable to start
MSExcel" );
$objXLApp->Workbooks->Open( "c:\\temp\\test .xls" );
$objXLSheet = $objXLApp->ActiveWorkBo ok->WorkSheets( $strSheetName );
$objXLCell = $objXLSheet->Range( $strCellName );
print "Cell $strCellName in $strSheetName: \"" . $objXLCell->Value() .
"\"\n";
// must do all of these to release resources correctly...
On 21 Dec 2004 02:07:18 -0800, "Steve" <googlespam@nas tysoft.com> wrote:
[color=blue]
>
>James Johnson wrote:[color=green]
>> I'd like to be able to read a microsoft spreadsheet with php. I know[/color]
>that php can read mysql, so I was thinking that maybe it could read
>excel spreadsheets as well.[color=green]
>>
>> Does anyone know if that can be done?
>>
>> Jim[/color]
>
>
>You could do this if you have MS Excel installed on the target machine,
>using PHP support for COM.
>
><?php
>
>$strSheetNam e = 'Sheet1'
>$strCellName = 'A1';
>
>$objXLApp = new COM( "excel.applicat ion" ) or die( "unable to start
>MSExcel" );
>$objXLApp->Workbooks->Open( "c:\\temp\\test .xls" );
>$objXLSheet = $objXLApp->ActiveWorkBo ok->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->ActiveWorkBo ok->Close();
>$objXLApp->Quit();
>
>unset( $objXLApp );
>
>?>
>
>---
>Steve[/color]
Exactly what I was looking for. I'll try it later today.
On Tue, 21 Dec 2004 06:12:32 -0500, James Johnson <jj@yaaho.com > wrote:
[color=blue]
>On 21 Dec 2004 02:07:18 -0800, "Steve" <googlespam@nas tysoft.com> wrote:
>[color=green]
>>
>>James Johnson wrote:[color=darkred]
>>> I'd like to be able to read a microsoft spreadsheet with php. I know[/color]
>>that php can read mysql, so I was thinking that maybe it could read
>>excel spreadsheets as well.[color=darkred]
>>>
>>> Does anyone know if that can be done?
>>>
>>> Jim[/color]
>>
>>
>>You could do this if you have MS Excel installed on the target machine,
>>using PHP support for COM.
>>
>><?php
>>
>>$strSheetNa me = 'Sheet1'
>>$strCellNam e = 'A1';
>>
>>$objXLApp = new COM( "excel.applicat ion" ) or die( "unable to start
>>MSExcel" );
>>$objXLApp->Workbooks->Open( "c:\\temp\\test .xls" );
>>$objXLSheet = $objXLApp->ActiveWorkBo ok->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->ActiveWorkBo ok->Close();
>>$objXLApp->Quit();
>>
>>unset( $objXLApp );
>>
>>?>
>>
>>---
>>Steve[/color]
>
>Exactly what I was looking for. I'll try it later today.
>[/color]
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?
James Johnson wrote:[color=blue]
> Can you point me to any examples that get the number of rows &[/color]
columns and loops[color=blue]
> through these? Or, where can I find documentation on these (php[/color]
related) functions?
In this example PHP provides only the creation of the object $objXLApp
using the COM support class. See
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.
An noise sounding like James Johnson said:[color=blue]
> On Tue, 21 Dec 2004 06:12:32 -0500, James Johnson <jj@yaaho.com > wrote:
>[color=green]
>>On 21 Dec 2004 02:07:18 -0800, "Steve" <googlespam@nas tysoft.com> wrote:
>>[color=darkred]
>>>
>>>James Johnson wrote:
>>>> I'd like to be able to read a microsoft spreadsheet with php. I know
>>>that php can read mysql, so I was thinking that maybe it could read
>>>excel spreadsheets as well.
>>>>
>>>> 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
>>>
>>>$strSheetNam e = 'Sheet1'
>>>$strCellNa me = 'A1';
>>>
>>>$objXLApp = new COM( "excel.applicat ion" ) or die( "unable to start
>>>MSExcel" );
>>>$objXLApp->Workbooks->Open( "c:\\temp\\test .xls" );
>>>$objXLShee t = $objXLApp->ActiveWorkBo ok->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->ActiveWorkBo ok->Close();
>>>$objXLApp->Quit();
>>>
>>>unset( $objXLApp );
>>>
>>>?>
>>>
>>>---
>>>Steve[/color]
>>
>>Exactly what I was looking for. I'll try it later today.
>>[/color]
>
> 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?
>[/color]
Check out VBA for excel. That'll tell you what you need to know. Do the stuff
up in excel and you'll see how to loop through row and columns, just open the
vb editor under tools and play around, then port your code to php.
db
--
/(bb|[^b]{2})/
Trees with square roots don't have very natural logs.
Comment