Excel to HTML

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
big_c147
Forum Newbie
Posts: 15
Joined: Wed Jun 22, 2005 9:32 am

Excel to HTML

Post by big_c147 »

Hi Guys

What I want to be able to do it to save a Excel file as HTML page. I know this can be done manually but what I want is the user to upload a excel file it then be converted to html (Effectively doing a File, Save as in Excel) automatically. Does anyone have any idea where to start or any sample code?

I have written code to upload the file which works fine but I don’t know how to save the excel file as a webpage

Thanks
Craig
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Until Open Office comes up with some PHP extension for office documents manipulation, you'll need to use PHP's COM
big_c147
Forum Newbie
Posts: 15
Joined: Wed Jun 22, 2005 9:32 am

Post by big_c147 »

Thanks for the reply. I found this code on the page you linked to which originally saved the file as .csv I have adapted it so it will save as .htm However i dont know the number at the end of the Save As line. (as commented below)

Here is it code

Code: Select all

<?php
// starting excel 
$excel = new COM("excel.application") or die("Unable to instanciate excel"); 
print "Loaded excel, version {$excel->Version}\n"; 

//bring it to front 
#$excel->Visible = 1;//NOT
//dont want alerts ... run silent 
$excel->DisplayAlerts = 0; 

//open  document 
$excel->Workbooks->Open("C:\\phpdev\\www\\Rename\\test.xls"); 
echo"<br>file opened<br>";
//XlFileFormat.xlcsv file format is 6
//saveas command (file,format ......)
$excel->Workbooks[1]->SaveAs("C:\\phpdev\\www\\Rename\\test.html",6);\\the number at the end of this line 
echo"Save as worked<br>";

//closing excel 
$excel->Quit(); 
echo"Excel closed<br>";

//free the object 
$excel->Release(); 
echo"file closed<br>";

$excel = null; 
?>
Is there a list of numbers and which type of file they are saved as or does anyone no which number i need to use?

Thanks
Craig
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

load up excel and count.. :?
big_c147
Forum Newbie
Posts: 15
Joined: Wed Jun 22, 2005 9:32 am

Post by big_c147 »

Hi

I Have done that.... The original example which works is for saving to CSV which is number 6 in the code, However when i open excel and count down the different formats it can be saved in its the 8th option :?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

well.. the numbers should be quite simple since it should be sequencial.. so just try a bunch.. see which one works.. :?
big_c147
Forum Newbie
Posts: 15
Joined: Wed Jun 22, 2005 9:32 am

Post by big_c147 »

Hi

I have done from numbers 1-11 after that it errors out....none of which save in the correct format...Here is my code are there any mistakes in it?

Code: Select all

<?php
// starting excel 
$excel = new COM("excel.application") or die("Unable to instanciate excel"); 
print "Loaded excel, version {$excel->Version}\n"; 

//bring it to front 
#$excel->Visible = 1;//NOT
//dont want alerts ... run silent 
$excel->DisplayAlerts = 0; 

//open  document 
$excel->Workbooks->Open("C:\\phpdev\\www\\Rename\\test.xls"); 
echo"<br>file opened<br>";
//XlFileFormat.xlcsv file format is 6
//saveas command (file,format ......)
$excel->Workbooks[1]->SaveAs("C:\\phpdev\\www\\Rename\\test.htm",6); 
echo"Save as worked<br>";

//closing excel 
$excel->Quit(); 
echo"Excel closed<br>";

//free the object 
$excel->Release(); 
echo"file closed<br>";

$excel = null; 
?>
Post Reply