在windows上使用php将excel导出为html
我在 Windows 上使用 xampp/wamp 并希望将 Excel 工作簿转换为 html 文件。
我不会立即问这个问题,我做了很多研究,最终设法达到了一个点,但被困在这里。
我使用 php 的 COM 库打开 excel,然后读取工作簿并尝试将其保存为 html,但我遇到了问题
这是我的代码
$excel = new COM("Excel.Application",NULL,CP_UTF8) or die("Unable to instantiate Excel");
$excel->Application->Visible=1;
$excel->DisplayAlerts="False";
$workBook=$excel->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;
PUlishObjects 方法不断告诉我 xlSourceSheet 未定义,我试图传递它作为字符串“xlSourceSheet”,但它一直说其中一个参数类型不匹配。在上面的例子中,它说参数6类型不匹配;
如果我删除诸如 divid 和 title (最后 2 个)之类的可选参数,它会显示源范围的类型不匹配,由于正在导出工作表,该范围显然为空。
任何人都可以阐明这一点并告诉我我做错了什么。
谢谢
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->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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无论如何,我通过进一步深入研究 Excel 开发人员手册,设法解决了这个问题。
我只需将 xlSourceSheet 和 xlHtmlstatic 替换为我在文档中找到的各自的数字。 xlSourceSheet 为 1,xlHtmlStatic 为 0。
如果有人正在寻找这些代码,这里是
xlSourceAutoFilter 3 An AutoFilter range
xlSourcePivotTable 6 数据透视表
xlSourcePrintArea 2 选择用于打印的单元格范围
xlSourceQuery 7 查询表(外部数据范围)
xlSourceRange 4 单元格范围
xlSourceSheet 1 整个工作表
xlSourceWorkbook 0 工作簿
xlHtmlCalc 1 使用电子表格组件。在 Excel 2007 中已弃用。
xlHtmlChart 3 使用图表组件。在 Excel 2007 中已弃用。
xlHtmlList 2 使用数据透视表组件。在 Excel 2007 中已弃用。
xlHtmlStatic 0 使用静态(非交互式)HTML 仅用于查看。
谢谢茨维斯克:)
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.
Thanks cweiske :)