将 HTML 转换为 Excel?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9566350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Converting HTML to Excel?
提问by Saicharan S M
I know that Excel is capable of opening HTML files directly. But the content of the file will still be HTML. Is there any way I can change the contents of the file from HTML to XLS or XLSX?
我知道 Excel 能够直接打开 HTML 文件。但文件的内容仍将是 HTML。有什么方法可以将文件的内容从 HTML 更改为 XLS 或 XLSX?
回答by Robert Mearns
So long as Excel can open the file, the functionality to change the format of the opened file is built in.
只要 Excel 可以打开文件,就内置了更改打开文件格式的功能。
To convert an .htmlfile, open it using Excel (File - Open) and then save it as a .xlsxfile from Excel (File - Save as).
要转换.html文件,请使用 Excel(文件 - 打开)打开它,然后从 Excel将其另存为.xlsx文件(文件 - 另存为)。
To do it using VBA, the code would look like this:
要使用 VBA 执行此操作,代码将如下所示:
Sub Open_HTML_Save_XLSX()
Workbooks.Open Filename:="C:\Temp\Example.html"
ActiveWorkbook.SaveAs Filename:= _
"C:\Temp\Example.xlsx", FileFormat:= _
xlOpenXMLWorkbook
End Sub
回答by gamov
We copy/paste html pages from our ERP to Excel using "paste special.. as html/unicode" and it works quite well with tables.
我们使用“特殊粘贴.. 作为 html/unicode”将 html 页面从我们的 ERP 复制/粘贴到 Excel,它与表格一起工作得很好。
回答by Parag Mande
Change the content type to ms-excel in the html and browser shall open the html in the Excel as xls. If you want control over the transformation of HTML to excel use POI libraries to do so.
将 html 中的内容类型更改为 ms-excel,浏览器应将 Excel 中的 html 以 xls 格式打开。如果您想控制 HTML 到 excel 的转换,请使用 POI 库来实现。