将带有html标签的文本转换为格式化的word文件
如何将带有html标签的文本转换为格式化的word文档。 其实我需要做的是 我想在文本框中输入带有 html 标签的文本,当我单击按钮时,我希望在 Word 文档中打开文本,其中删除了 html 标签,并且文本以其相应的格式显示。
How can i convert the text with html tag to formated word document.
Actually what i need to do is,
I want to give text with the html tag as input in a text box, and when i click a button, i want the the text to be open in a word document where the html tags are removed and the text appears in its corresponding format.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想知道当您将 HTML 文件另存为 Word 文档时,您是否会遇到格式丢失的问题。我是。我发现多个类不会被继承,也不会基于多个类。
考虑一下:
结果:
p
是绿色的,因为它的第一个声明包含p
不是蓝色的,因为该声明是“无效”多类声明的一部分 (!)span
不是红色,也不是蓝色,因为“无效”的多类声明-
由于根据上述发现,我最终将元素包装在另一个元素中,始终使用单个标记类名,并在此基础上成功格式化内容。
请注意,可以使用 Javascript 操作元素,根据需要添加/删除额外的类名,Word 只对它尝试解析的 HTML 文件中的实际标记感兴趣。
我不明白的是如何让CSS背景图像在Word打开HTML文件时显示出来。我通常使用快捷方式:
background:transparent url(../img/icon-audio-16.gif) left top no-repeat;
这不起作用(是的,检查了我的路径),但随后也没有逐一分解:无论如何......
I wonder if you were stuck by the loss of formatting when you saved an HTML file as a Word doc. I was. I figured out that multiple classes are not carried over, nor anything based on multiple classes.
Consider this:
Results in:
p
is green because its first declaration holdsp
is not blue because that declaration is part of an 'invalid' multi-class declaration (!)span
is orange because its first declaration holdsspan
is not red, nor blue, because of the 'invalid' multi-class declarations--
As a result of the above findings, I ended up wrapping my elements in another element, always with a single markup class name, and formating things successfully on that basis.
Note that it's fine to manipulate elements with Javascript, adding/removing extra class names as required, Word is only interested in the actual markup in the HTML file it is trying to parse.
What I didn't figure out is how to get CSS background images to show up when HTML files are opened by Word. I usually use the shortcut:
background:transparent url(../img/icon-audio-16.gif) left top no-repeat;
which didn't work (yes, checked my paths), but then neither did a blow-by-blow breakdown:Anyway...
制作一个常规的 html 文件并以 .doc 扩展名保存。它将在ms word中很好地显示。
Make a regular html file and save it with .doc extension. It will be well displayed in ms word.