Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to insert html into a MS word file by asp.net c#.

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

C#
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);


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,
Posted
Updated 9-Jul-17 4:42am
v3

1 solution

Quote:
I want to use Microsoft.Office.Interopt.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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900