Is it possible to convert an HTML document to Excel with multiple Worksheets/tabs?

♀尐吖头ヾ 提交于 2019-12-20 04:35:02

问题


I know we can send regular html files through the tubes and have the browser open them as Excel documents (you do that by changing http headers and the file name, then excel does the conversion). BUT, is it possible to get an HTML document show up in Excel with two Worksheets/Tabs?

Here's what I thought might work, but didn't quite get the job done:

<html>
  <body>
    <table>
      ....
    </table>
    <hr class='pageBreak' />      <= I thought perhaps this would divide stuff up
    <table>
      ....
    </table>
  <body>
</html>

Is there a worksheet tab or some kind of namespace I could ADD to html in order to create multiple worksheets?

EDIT Just curious if anyone else has any ideas... :-/

(I'm using Ruby, so if you know of a library that will convert HTML tags to an Excel worksheet object of some sort, that might work too)


回答1:


Try Ruby POI for generating OLE documents like Excel spreadsheets ( http://poi.apache.org/poi-ruby.html ).

The ExcelParser gem is wonderful if you need to handle importing .xls files as well ( http://raa.ruby-lang.org/project/parseexcel/ ).




回答2:


You need to use MHTML to do multiple tabs. You can put the workbook information (which includes defining each of your tabs and the title that will appear on the tab) and the first tab data into an HTML file.

But to specify the content for each tab beyond the first, you have to use the mhtml spec and put a separator in between each table.

This will get you started on:Multipart HTML

I have not been able to find a tutorial to walk novices through the process.



来源:https://stackoverflow.com/questions/2213702/is-it-possible-to-convert-an-html-document-to-excel-with-multiple-worksheets-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!