简体   繁体   English

使单词解析HTML格式

[英]Making word parse HTML formatting

We've got a JSP that utilizes the NicEdit online texteditor to format text using JavaScript. 我们有一个JSP,它利用NicEdit在线文本编辑器来使用JavaScript格式化文本。 The "submit" button runs a servlet that uploads the message string to our MySQL database, following which it prints the string on paper using the following code: “提交”按钮运行一个Servlet,它将消息字符串上载到我们的MySQL数据库,然后使用以下代码在纸上打印该字符串:

POIFSFileSystem fs = new POIFSFileSystem();
DirectoryEntry directory = fs.getRoot();
directory.createDocument("WordDocument", new ByteArrayInputStream(content.getBytes()));
                        FileOutputStream out = new FileOutputStream(filename);
fs.writeFilesystem(out);
out.close();

Desktop.getDesktop().print(destinationFile);

My question is, how do we keep the formatting on the printed page (bold, italic etc.) instead of it printing 我的问题是,如何将格式保留在打印页面上(粗体,斜体等)而不是打印

< b>, < i>, < u> tags? <b>,<i>,<u>标签?

I must admit I haven't done much pre-research, because I don't really know what to look for? 我必须承认我没有做太多的预研究,因为我真的不知道要寻找什么?

Thanks a lot, 非常感谢,

JAMM 卡姆

First, there are a bunch of formats you could submit to Word: doc, docx, rtf, html, Word 2003 XML, Flat OPC XML ... 首先,您可以将多种格式提交给Word:doc,docx,rtf,html,Word 2003 XML,Flat OPC XML ...

This answer is specific to docx (though it looks like you might be sending .doc - not sure whether you are committed to that), where there are two ways you can handle HTML. 这个答案是特定于docx的(尽管看起来您可能正在发送.doc-不确定是否要提交给它),其中有两种处理HTML的方式。

The first is to create an altChunk/alternative format input part containing the HTML, which Word can process when the docx is first opened. 第一种是创建一个包含HTML的altChunk /替代格式输入部分,Word可以在首次打开docx时进行处理。

The second is to convert the HTML yourself. 第二个是自己转换HTML。 As from 2.8.0, docx4j (to which I'm a committer) can convert XHTML to docx content. 从2.8.0版本开始,docx4j(我是提交者)可以将XHTML转换为docx内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM