将带有html标签的文本转换为格式化的word文件

发布于 2024-08-03 05:58:26 字数 122 浏览 1 评论 0原文

如何将带有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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

§对你不离不弃 2024-08-10 05:58:26

我想知道当您将 HTML 文件另存为 Word 文档时,您是否会遇到格式丢失的问题。我是。我发现多个类不会被继承,也不会基于多个类。

考虑一下:

<p class="class1">This <span class="class1 class2">is my</span> text.</p>

.class1 { color:green; }
.class2 { color:orange; }

.class1.class2 { color:red; }

.class1.class2,
.class1 { color:blue; }

结果:

  1. p 是绿色的,因为它的第一个声明包含
  2. p 不是蓝色的,因为该声明是“无效”多类声明的一部分 (!)
  3. < code>span 是橙色的,因为它的第一个声明
  4. 与第 2 点一样。 span 不是红色,也不是蓝色,因为“无效”的多类声明

-

由于根据上述发现,我最终将元素包装在另一个元素中,始终使用单个标记类名,并在此基础上成功格式化内容。

请注意,可以使用 Javascript 操作元素,根据需要添加/删除额外的类名,Word 只对它尝试解析的 HTML 文件中的实际标记感兴趣。

我不明白的是如何让CSS背景图像在Word打开HTML文件时显示出来。我通常使用快捷方式: background:transparent url(../img/icon-audio-16.gif) left top no-repeat; 这不起作用(是的,检查了我的路径),但随后也没有逐一分解:

background-color:transparent;
background-image:url(../img/icon-audio-16.gif);
background-position:left top;
background-repeat: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:

<p class="class1">This <span class="class1 class2">is my</span> text.</p>

.class1 { color:green; }
.class2 { color:orange; }

.class1.class2 { color:red; }

.class1.class2,
.class1 { color:blue; }

Results in:

  1. p is green because its first declaration holds
  2. p is not blue because that declaration is part of an 'invalid' multi-class declaration (!)
  3. span is orange because its first declaration holds
  4. As with point 2. span 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:

background-color:transparent;
background-image:url(../img/icon-audio-16.gif);
background-position:left top;
background-repeat:no-repeat;

Anyway...

白鸥掠海 2024-08-10 05:58:26

制作一个常规的 html 文件并以 .doc 扩展名保存。它将在ms word中很好地显示。

Make a regular html file and save it with .doc extension. It will be well displayed in ms word.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文