How to convert word into html

Source: Internet
Author: User
Tags website server

Previously, I used word to convert to HTMl. I found a similar piece of code on the Internet and found that a lot of code could not be executed. After debugging, I finally got it done for half a day.

The method is followed by the word file path. To execute such code, you need to add Microsoft. Office. Interop. Word. dll reference.

/// <Summary>
/// Convert Word to HTML
/// </Summary>
/// <Param name = "path"> </param>
Private string WordToHTMl (ref string path)
{
String pageUrl = null;

Object fltDocFormat = 10; // For filtered HTML Output
Object missing = System. Reflection. Missing. Value;
Object readOnly = false; // Open file in readOnly mode
Object isVisible = false; // The process has to be in invisible mode
Object fileName = path;

// Obtain the path of the website Server
String newPath = System. Web. HttpContext. Current. Server. MapPath ("/ConvertFiles /");
String newFileName = System. IO. Path. GetFileNameWithoutExtension (fileName. ToString ());
Object saveFileName = newPath + savePath + newFileName + ". html ";

// Determine whether the file is converted
If (! System. IO. File. Exists (SaveFileName ))
{

Microsoft. Office. Interop. Word. ApplicationClass objWord = new Microsoft. Office. Interop. Word. ApplicationClass ();
// Open the Word Document
ObjWord. documents. open (ref fileName, ref readOnly, ref missing, ref isVisible, ref missing, ref missing, ref missing );
// Do the background activity
ObjWord. Visible = false;
Microsoft. Office. Interop. Word. Document oDoc = objWord. ActiveDocument;

ODoc. saveAs (ref saveFileName, ref fltDocFormat, ref missing, ref missing, ref missing, ref missing );
ODoc. Close (ref missing, ref missing, ref missing );
ObjWord. Quit (ref missing, ref missing, ref missing );
// Process [] myProcesses = Process. GetProcessesByName ("WINWORD ");
// Foreach (Process myProcess in myProcesses)
//{
// MyProcess. Kill ();
//}

// String pageUrl = newFileName + ". html ";
// System. Web. HttpContext. Current. Server. Transfer (pageUrl );
}

Else
{
// Page path
PageUrl = IpPath + FileName + ". html ";

}
Return pageUrl;


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.