为什么我用word文档转换成html格式后表格边框不见了,从HTML页面转换到MS Word 2003时,表格边框无法正确显示(Table borders don't display properly...

从HTML页面转换到MS Word 2003时,表格边框无法正确显示(Table borders don't display properly when converted from HTML page into MS Word 2003)

我有一些复杂的设置。 我专注于为第三方系统编写的XSLT。 所有的CSS在浏览器中看起来都不错。 现在,该系统提供了一个按钮,可将我生成的HTML转换为MS Word 2003。

但是,表格边框不会像在浏览器中显示那样进行转换。 有很多表,他们有不同的边界设置。 例如,有一个只使用外部边界并且没有边界。 转换为MS Word时,将显示一个表格,其中所有边框位于单元格之间。 我不想要的。

我试过搜索互联网,但没有遇到任何有用的东西。 也许有关于如何设置表格边框的提示或技巧,以便通过MS Word正确理解。

第三方说:“系统只是通过它在安装的Word版本中找到的转换器创建的HTML”。

我真的很感激任何提示和帮助!

I've got a bit of a complicated set up. I specialise in XSLT which I write for 3rd party system. All CSS looks fine in the browser. Now that system provides a button that converts my generated HTML into MS Word 2003.

However, table borders don't convert as they appear in a Browser. There are lots of tables and they have different borders setup. For example there is one that uses only outside border and no borders inside it. When converting to MS Word, a table appears with ALL the borders in between cells. Which I don't want.

I've tried search the Internet, but didn't come across anything useful. Maybe there are tips or tricks on how to set up tables borders so it's understood properly by MS Word.

The third party said the following: "The system just passes the HTML created through the converter it finds in the installed version of Word".

I would really appreciate any tips and help!

原文:https://stackoverflow.com/questions/2515041

更新时间:2019-11-19 10:00

最满意答案

我试图得到只有外部边界和没有内部边界的桌子。 我一直在尝试下面的HTML:

但是,在Word中,该表格同时具有外部边界和内部边界,而不仅仅是外部边界,因为我试图获取它。

那么,这是border作用。 嗯。 你说内联CSS没有被拾起,所以我猜这两个:

或用

围住桌子

将无法工作? 那些将是最优雅的解决方案。

如果所有这些都失败了,为什么不把桌子放进桌子呢?

从网页设计的角度来看,2010年使用这种做法是一种可怕的做法,但如果这是唯一的解决方法,那么您可以正确导入页面,也许这是必要的。 我很确定,但是某种形式的CSS 必须工作。 也许是不同的符号或其他东西。 但我不是Word HTML专家。

I was trying to get a table with only the outer border and no inside ones. I've been trying the following HTML:

However, in the Word that table appears with both outer and inner borders, not just with outer border as I was trying to get it.

Well, that is what border does. Hmm. You say inline CSS doesn't get picked up, so I guess both this:

or surrounding the table with a

won't work? Those would be the most elegant solutions.

If all that fails, why not put the table into a table?

it's a horrible practice to use in 2010 from a web design point of view, but if it's the only workaround so you can import the page correctly, maybe it's necessary. I'm pretty sure however that some form of CSS must work. Maybe a different notation or something. But I'm no Word HTML expert.

相关问答

你想达到的保真度是多少? 我非常确定这样做的“最简单”方法是将文档转换为XPS服务器端(可能使用XPS打印机),然后对其进行操作以创建Silverlight兼容内容(XAP) 为什么这个? 因为,例如: Silverlight不支持流文档,因此您不希望必须在客户端上执行布局。 Silverlight要求字体包含在使用它的同一个XAP中(即使在同一个程序集中),因此您需要生成一个在服务器端嵌入字体的程序集。 XPS是一个拉链的XAML(因此管理比Word2003 doc好得多),但它不是Silver

...

我试图得到只有外部边界和没有内部边界的桌子。 我一直在尝试下面的HTML:

...

你可以使用Selection.Information(wdFirstCharacterLineNumber) = 1 。 If Selection.Information(wdFirstCharacterLineNumber) = 1 Then

Selection.TypeText Text:="top of page"

Else

Selection.TypeParagraph

Selection.TypeText Text:="not top of page"

End If

...

你可能想尝试word-break: break-word; body, table.body, td, th {

word-break: break-word;

}

这应该解决问题 I got a fix for the issue. Use w:DontGrowAutofit (word XML element) in html header part.

...

啊哈! 我找到了。 我正在尝试一种方法来做到这一点,但我发现,如果我只是编辑每一行,因为我将数据添加到它,那么我可以这样得到整个表。 这是我添加到我的Foreach循环中的行: $Table.Rows($x).Borders.InsideLineStyle = 0

如果有人知道的话,我仍然会喜欢链接到一些很好的文档! Aha! I found it. I was trying for a way to do it in one line, but I found that if I just e

...

我会选择Ashwini Raman的建议。 它不适用于每种情况。 在复杂的HTML文档的情况下,许多图像和东西字不会做得很好。 但对大多数情况来说应该没问题。 否则,你面前有一项复杂的任务。 例如,您必须使用jsoup库解析HTML文档,然后使用docx4j库来创建工作文档。 两者的链接在这里: http://www.docx4java.org/trac/docx4j http://jsoup.org/ 当你这样做时,格式可能是iffy。 要回答您的原始问题,没有现成的库可以满足您的期望。 至少我

...

您可能需要考虑使用基于Microsoft Excel自动化类 (Excel 97开发人员工具包中的AutoXL的端口)的VC ++ / MFC的Word自动化类 。 它适用于所有版本的MS Word(包括2003/2007)。 You may want to consider using the Word Automation Class for VC++/MFC, which is based on the Microsoft Excel Automation Class (a port of

...

你的地图是否必须插入zero_width_joiner? halant(virama)本身足以获得半辅音(对于某些组合),特别是,Word可能是使用ZWJ的存在来保持它们分开。 如果摆脱ZWJ没有帮助,另一种可能性是Word可能将文本字符串的各个字符视为文本的单独“运行”。 如果前4个字符不在一次运行中,则可能发生这种情况。 [旁白:判断它是否被视为单次运行的方法是将文档保存为xml文件,然后使用notepad ++之类的东西打开它,并查看与这些相关的xml“w:t”元素(IIRC)字符。 如果它

...

这个工具可以清除Word生成的html文件中的额外垃圾,我已经使用了一段时间了。 http://www.wordhtmlcleaner.co.uk/ 然后,您可以使用此工具重新格式化代码,以便您可以更轻松地找到要查找的表格: http://www.dirtymarkup.com/ 希望这可以帮助! 编辑: 试试这个工具 。 有了这些选项: Doctype : auto

Drop empty paras

Logical emphasis

Output XHTML

Word 2000

这似乎

...

我对COM一无所知,但是在MSDN上围绕Word API文档wsFormatFilteredHTML ,看起来最好的办法是使用Document.SaveAs将wsFormatFilteredHTML保存为临时文件,然后将该HTML提供给用户。 一定要选择过滤的 HTML,否则你会得到最有史以来最汤的标签汤。 I know nothing about COM, but poking around the Word API docs on MSDN, it looks like your best b

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以使用Apache POI库来实现将Word文档转换HTML格式文本。以下是一个简单的Java代码示例: ```java import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.converter.WordToHtmlConverter; import org.apache.poi.hwpf.usermodel.Range; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import java.io.*; public class WordToHtmlConverterExample { public static void main(String[] args) { String inputFilePath = "input.doc"; String outputFilePath = "output.html"; try (InputStream inputStream = new FileInputStream(inputFilePath); HWPFDocument document = new HWPFDocument(new POIFSFileSystem(inputStream)); Writer writer = new BufferedWriter(new FileWriter(outputFilePath))) { Range range = document.getRange(); WordToHtmlConverter converter = new WordToHtmlConverter(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()); converter.processDocument(document); org.w3c.dom.Document htmlDocument = converter.getDocument(); writer.write(htmlDocumentToString(htmlDocument)); } catch (IOException | ParserConfigurationException e) { e.printStackTrace(); } } private static String htmlDocumentToString(org.w3c.dom.Document document) throws IOException { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(document), new StreamResult(writer)); return writer.toString(); } } ``` 请确保在运行代码之前已经将Apache POI库添加到您的项目中。此代码将读取名为`input.doc`的Word文档,并将其转换HTML格式,并将结果写入名为`output.html`的文件中。 请注意,这只是一个简单的示例,对于更复杂的文档,可能需要额外的处理和调整来保留样式和格式

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值