通过ASP.NET C#将HTML插入MS word [英] Insert HTML into MS word by ASP.NET C#

查看:148
本文介绍了通过ASP.NET C#将HTML插入MS word的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过asp.net c#将html插入到MS word文件中。



我使用的是Microsoft.Office.Interopt.Word。这是我的代码:



I want to insert html into a MS word file by asp.net c#.

I used Microsoft.Office.Interopt.Word. This is my code :

Word.Application wordApplication = new Word.Application();

Word._Document wordDocument = wordApplication.Documents.Add();
Word.Selection selection = wordApplication.Selection;
selection.InsertFile("MyHtmlFilePath.htm");

// Save the document to it's output file.
wordDocument.SaveAs(ref outputFile);





但是有一个问题,如果我有一个Time New Roman字体系列,在插入html到word后,该行没有Time New Roman字体系列。



InsertFile方法面两个单词或多个单词字体系列的问题(如Times New Roman,Comic Sans MS,...)



我也不想使用第三个派对dll喜欢aspose 和....



预先感谢您的帮助。



我尝试了什么:



我想使用Microsoft.Office.Interopt.Word。



使用aspose dll我解决了这个问题,但我不想使用第三方dll的

我尝试将html复制到剪贴板通过c#代码粘贴到word文件中,但我可以t。



请帮我解决这个问题,



But there is a problem, if i have a line with Time New Roman font family, after insert html to word , that line doesn't have Time New Roman font family.

InsertFile method faces problem with two words or multiple words font family (Like Times New Roman, Comic Sans MS , ...)

I also don't want use third party dll's Like aspose and ... .

Thanks in advance for your help.

What I have tried:

I want to use Microsoft.Office.Interopt.Word .

with aspose dll I solved this problem but I don't want to use third party dll's.
I try to copy html to clipboard and paste in word file by c# code, but I can't.

Please help me to solve this problem,

推荐答案

Quote:

我想使用Microsoft.Office.Interopt.Word。

I want to use Microsoft.Office.Interopt.Word .



你不能。服务和Web应用程序不支持Office Interop。 Office不是可重入的,这意味着如果您同时从两个不同的请求输入Office代码,就会发生不可预测的事情。



此外,还有一些函数会导致在用户桌面上弹出一个对话框。嗯,是服务和Web应用程序,该对话框在服务器上弹出,永远等待永远不会响应的响应。



使用其中一个SDK,如OpenXML SDK,ClosedXML SDK,您想要做的任何其他事情。您将不得不查阅您使用的SDK上的文档,以了解如何将文件附加到Word文档。


You can't. Office Interop is not supported in services and web applications. Office is not reentrant, which means unpredicatble things happen if you enter the Office code from two different requests at the same time.

Also, there are some functions that result in a dialog popping up on the users desktop. Well, is service and web applications, that dialog pops up on the server, waiting forever for a response that will never come.

Use one of the SDK's, like the OpenXML SDK, the ClosedXML SDK, of whatever else you want to do this. You're going to have to consult the documentation on the SDK you use to find out how to attach a file to a Word document.


这篇关于通过ASP.NET C#将HTML插入MS word的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆