Word to HTML

Source: Internet
Author: User

private void E_docx (string f_o)
{
Bll. MEDICALTYPEBLL mdl = new BLL. MEDICALTYPEBLL ();
Hiddenfield1.value = mdl. D_medicals (F_o). rows[0]["Medical_templet"]. ToString ();
Microsoft.Office.Interop.Word.ApplicationClass Word = new Microsoft.Office.Interop.Word.ApplicationClass ();
Type Wordtype = Word. GetType ();
Microsoft.Office.Interop.Word.Documents docs = Word. Documents; Open File
Type Docstype = Docs. GetType ();
Object fileName = Server.MapPath ("~/uploadimgs/") + MDL. D_medicals (F_o). rows[0]["Medical_templet"]. ToString ();
Microsoft.Office.Interop.Word.Document doc = (Microsoft.Office.Interop.Word.Document) docstype.invokemember (" Open ", System.Reflection.BindingFlags.InvokeMethod, NULL, Docs, new object[] {fileName, True, true}); Convert format, Save As
Type DocType = doc. GetType ();
Encoding code = encoding.getencoding ("gb2312");
String str = DateTime.Now.ToString ("Yyyymmddhhmmss");
FileName = str + ". htm";
StreamWriter SW = new StreamWriter (Server.MapPath ("htm/") + FileName, false, code);
Sw. Close ();
Object savefilename = Server.MapPath ("htm/") + fileName;
Save HTML

Doctype.invokemember ("SaveAs", System.Reflection.BindingFlags.InvokeMethod, NULL, doc, new object[] {savefilename, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML});
Quit Word
Object saveChanges = System.Reflection.Missing.Value;
Object originalformat = System.Reflection.Missing.Value;
Object routedocument = System.Reflection.Missing.Value;
Docs. Close (ref saveChanges, ref originalformat, ref routedocument);
Doc. Close (ref saveChanges, ref originalformat, ref routedocument);
Wordtype.invokemember ("Quit", System.Reflection.BindingFlags.InvokeMethod, NULL, Word, NULL);

FileStream tfile = File.Open (savefilename.tostring (), FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader (tfile, code);
StringBuilder sb = new StringBuilder (Sr. ReadToEnd ());
String subs = String. Empty;
int ibeginindex = sb. ToString (). IndexOf ("<body");
int iendindex = sb. ToString (). LastIndexOf ("</body>");
int see = sb. ToString (). Length;
Subs = sb. ToString (). Substring (Ibeginindex, Iendindex-ibeginindex). Replace ("<body", "<div");
Subs = sb. ToString (). Replace ("</body>", "</div>");
Subs = subs. Replace (str + ". Files", "htm/" + str + ". Files");
Subs = subs. Replace ("V:imagedata", "image");
int NUM1 = subs. ToLower (). IndexOf ("<table");
int num2 = subs. ToLower (). LastIndexOf ("</table>");
STR1 = subs. Substring (0, NUM1);
STR2 = subs. Substring (NUM2);

Div1. InnerHtml = subs. ToString ();

}

Word to HTML

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.