Basic Ideas:
Upload a Word file to the server, read its content and store it as Html, and then load the Html content.
1: Use the Microsoft. Office. Interop. Word component
This is a common method, and the code will not be pasted out. There are a lot of examples on the Internet.
Disadvantage: the server needs to install the Word component and set the Docm + object permission on the server. If one server is okay, it is cumbersome to apply the project to multiple different servers.
2: OpenXml API
You can convert .docx (word 97-2003 is not applicable) to XML. It is no longer a problem to convert it to HTML or other formats. This Api requires. net FreamWork3.5 + Office2007 +
3: Third-Party: for example, Aspose. Words (tested and recommended)
Aspose provides various format conversion solutions. If you are interested, please take a closer look ,. NET Java, which adopts Aspose. words this Dll, without installing Microsoft Office components can be converted Word (Converting DOC, docx to HTML without MS Office Word in. net)Copy codeThe Code is as follows: Aspose. Words. Document d = new Aspose. Words. Document (wordPhysicalPath );
D. Save ("d: \ 1.html", SaveFormat. Html );
You can save it as an HTML document (note that the images in the Word are stored in the same directory as the Html file, and you need to replace Advantage: you do not need to install the Microsoft Office component. You only need a DLL of about 2 MB to complete this function.
Disadvantage: Aspose is not an open-source component. Although there is a cracked version in China, it can be decompiled and modified by itself. However, the copyright issue is indeed a factor to consider.
There are other third-party projects, most of which are charged, which will not be listed here.