Page 1 of 1

Excel to HTML

Posted: Tue Aug 16, 2005 3:21 am
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

Posted: Tue Aug 16, 2005 3:26 am
by anjanesh
Until Open Office comes up with some PHP extension for office documents manipulation, you'll need to use PHP's COM

Posted: Tue Aug 16, 2005 4:18 am
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

Posted: Tue Aug 16, 2005 7:23 am
by feyd
load up excel and count.. :?

Posted: Tue Aug 16, 2005 7:26 am
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 :?

Posted: Tue Aug 16, 2005 7:54 am
by feyd
well.. the numbers should be quite simple since it should be sequencial.. so just try a bunch.. see which one works.. :?

Posted: Tue Aug 16, 2005 8:04 am
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; 
?>