How to convert an HTML document with lots of tables into a Word document?

匿名 (未验证) 提交于 2019-12-03 00:52:01

问题:

I have created an HTML document with many tables. How can I convert the document to Word?

The problem is that if I open an HTML document with Word, I get non-standard double-lines tables for some reason.

<table border="1" color="#000000" cellpadding="0" cellspacing="0" width=100%> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> </tr> <tr> <td width = 15%>0</td> <td width = 15%>0</td> <td width = 40%>0</td> <td> - </td> </tr> </table> 

回答1:

Most simple solution: Open the HTML in a browser, select the table (or the whole document) and copy and then paste into Word. You might get even better results when pasting into Excel, first, and then copy&paste from there to Word (kudos to Josiah for this tip). That often works pretty well, especially if the table looks good/correct in IE.

There are other solutions but they are much more complicated: You would need a HTML parser and something which can create OOXML files. If you want to try this, use Python with Beautiful Soup as HTML parser. Writing OOXML is explained in this question: How can I create a Word document using Python?

Note that the effort for this solution is probably 1-2 weeks.



回答2:

Solved the problem convert a lot of tables to Word document using css styles. After open Generate.html with Word all tables normal

File CSSTable.css

table.CSSTable { border-width: 1px; border-spacing: 0px; border-style: solid; border-color: black; border-collapse: collapse; background-color: white; } table.CSSTable th {     border-width: 1px;     padding: 0px;     border-style: solid;     border-color: black;     background-color: white;     -moz-border-radius: ; } table.CSSTable td {     border-width: 1px;     padding: 0px;     border-style: solid;     border-color: black;     background-color: white;     -moz-border-radius: ; } 

Generate.html

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf8"> <link rel="stylesheet" href="CSSTable.css" type="text/css"> </head> <body> <table class="CSSTable" width=100%> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> </tr> <tr> <td width = 15%>0</td> <td width = 15%>0</td> <td width = 40%>0</td> <td> - </td> </tr> </table> 


回答3:

You can use an altChunk, provided the document is to be opened in Word. Word is needed only for opening it.

In terms of Microsoft's OpenXML SDK classes: you will want AlternativeFormatImportPart of type AlternativeFormatImportPartType.Html

See this or this for examples



回答4:

From http://www.wordbanter.com/showthread.php?t=105850

"You have to go into the table, select "Table", then Table properties, then Options. Under "default cell spacing" deselect "allow spacing between cells."



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