开发者

Exporting excel to html using php on windows

开发者 https://www.devze.com 2023-03-12 05:58 出处:网络
I am using xampp/wamp on windows and looking to convert an excel workbook to a html file. I am not asking this question right away, i did a lot of research and finally managed to get to a point and g

I am using xampp/wamp on windows and looking to convert an excel workbook to a html file.

I am not asking this question right away, i did a lot of research and finally managed to get to a point and got stuck here.

Am using php's COM library to open excel, then read a workbook and try to save it as html, how ever i am having issues with it

This is my code

    $excel = new COM("Excel.Application",NULL,CP_UTF8) or die("Unable to instantiate Excel");
    $excel->Application->Visible=1;
    $excel->DisplayAlerts="False";
    $workBook=$excel-开发者_JAVA技巧>Workbooks->Open(realpath("./example-03e-02.xlsx"));
     $workBook->PublishObjects->Add(xlSourceSheet, "c:\\temp\\x.htm", "Sheet1", "", xlHtmlStatic, "test_27778", "");
 $workBook->Publish (True);
 $workBook->AutoRepublish(0);
    $excel->Workbooks->Close();
    $excel->Application->Quit();
    $excel = null;
    $workBook=null;

The PUlishObjects method keeps telling me that xlSourceSheet is not defined, i tried to pass it as a string "xlSourceSheet" but it keeps saying parameter type mismatch in one or the other. IN the above case, it says parameter 6 type mismatch;

if i remove the optional parameters like divid and title (the last 2) it shows a type mismatch on source range which empty obviously since am exporting a sheet.

Any body can shed some light on this and tell me what i am doing wrong.

Thanks


Anywyas, i managed to sort out the problem with some further digging into excel developer manual.

I just had to replace xlSourceSheet and xlHtmlstatic with their respective numbers that i found in the docs. xlSourceSheet is 1 and xlHtmlStatic is 0.

If anybody is looking for these codes, here they are

xlSourceAutoFilter 3 An AutoFilter range xlSourcePivotTable 6 A PivotTable report xlSourcePrintArea 2 A range of cells selected for printing xlSourceQuery 7 A query table (external data range) xlSourceRange 4 A range of cells xlSourceSheet 1 An entire worksheet xlSourceWorkbook 0 A workbook

xlHtmlCalc 1 Use the Spreadsheet component. Deprecated in Excel 2007. xlHtmlChart 3 Use the Chart component. Deprecated in Excel 2007. xlHtmlList 2 Use the PivotTable component. Deprecated in Excel 2007. xlHtmlStatic 0 Use static (noninteractive) HTML for viewing only.

$object=$excel->ActiveWorkbook->PublishObjects->Add(1,"c:\\temp\\x.htm","Sheet1",0)->Publish(1);

Thanks cweiske :)

0

精彩评论

暂无评论...
验证码 换一张
取 消