473,854 Members | 1,507 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can php read .xls files directly?


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

Jul 17 '05 #1
5 20523

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

$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...

unset( $objXLCell );
unset( $objXLSheet );

$objXLApp->ActiveWorkBo ok->Close();
$objXLApp->Quit();

unset( $objXLApp );

?>

---
Steve

Jul 17 '05 #2
On 21 Dec 2004 02:07:18 -0800, "Steve" <go********@nas tysoft.com> wrote:

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'
$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


Exactly what I was looking for. I'll try it later today.
Jul 17 '05 #3
On Tue, 21 Dec 2004 06:12:32 -0500, James Johnson <jj@yaaho.com > wrote:
On 21 Dec 2004 02:07:18 -0800, "Steve" <go********@nas tysoft.com> wrote:

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

$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


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

Jul 17 '05 #4

James Johnson wrote:
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?

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

Jul 17 '05 #5
An noise sounding like James Johnson said:
On Tue, 21 Dec 2004 06:12:32 -0500, James Johnson <jj@yaaho.com > wrote:
On 21 Dec 2004 02:07:18 -0800, "Steve" <go********@nas tysoft.com> wrote:

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


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?

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.

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
14942
by: Batista, Facundo | last post by:
People: I'm trying to convert my father from using COBOL to Python, :) One difficult thing we stuck into is how to read, from python, files written with COBOL. Do you know a module that allows me to do that? It should avoid us the work to write a COBOL program that open the COBOL
2
3236
by: Jim Richards | last post by:
I have been told by a local PC club technician that 98SE cannot read NTFS drives in a network. Is this true? TIA, Jim.
3
5054
by: Kay | last post by:
IIS cannot read files in a directory reporting that : Microsoft VBScript runtime (0x800A01B6) Object doesn't support this property or method: 'Fso.GetFolder' This has to do with Scripting.FileSystemObject. I make sure the scrrun.dll is properly registered with regsvr32. Still the problem persists. Previously I do not know what I did right once in permission setting and
0
7022
by: Taran | last post by:
I am having this issue with both Visual C++ 6.0 and Visual Studio 2005 Beta 2. I have the SDK and DDK installed. I am trying to write a program to retrieve the EDID for a specific monitor in a multi-monitor system. I already know how to get this information from the registry, but I wish to get the EDID from the monitor directly. So far I have been unable to compile my program. The compiler generates over 102 errors and 54 warnings,...
8
3119
by: sophie_newbie | last post by:
Hey guys, OK this is a long shot but does anyone know of a way to uncompress tiff files directly in python. I know it can be done with an os call but that'll only work on unix and only if the right software is installed! I need to convert tiff images downloaded from uspto.gov to pdf, these images are compressed using G4, so I dunno if anyone knows of a method of doing this witout the os call! Surely there is a utility out there...
14
3601
by: IVETH | last post by:
Hi Can anyone provide an example of how to read files in java and upload this information to the database ? Thanks
4
1722
by: smartjoe85 | last post by:
can anyone give me a program to read files from my harddisk from dos environment
1
2444
by: pritdongare | last post by:
hiiiii, pritam here. i m doing xml parsing,,in dis i hav to take xml files one by one from folder and then parse them,,In this i won to know how to read files from folder.plz try to reply fast.
2
2596
mageswar005
by: mageswar005 | last post by:
How can i open doc,xls,html,swf files directly using php (without asking open,save,close options)? Regards, M.Mageswaran
0
9751
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11024
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10675
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10749
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9512
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7912
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5740
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4556
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4152
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.