当前位置:   article > 正文

asp.net中word转换为html,使用ASP.NET和C#将Microsoft Word doc文件转换为HTML文件

asp调用word模板dot生成html

protected void Button1_Click(object sender, EventArgs e)

{

if (FileUpload1.HasFile)

{

// When we click Button1, the file we specify is uploaded to a temporary

// folder, then converted into an html document...

string folder_to_save_in = @"c:\temp\documents\";

string filePath = folder_to_save_in + FileUpload1.FileName;

// This bit does the actual file upload:

FileUpload1.SaveAs(filePath);

// Here we set up a WOrd Application...

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

// Opening a Word doc requires many parameters, but we leave most of them blank...

object o_nullobject = System.Reflection.Missing.Value;

object o_filePath = filePath;

Word.Document doc = wordApplication.Documents.Open(ref o_filePath,

ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject,

ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject,

ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject);

// Here we save it in html format...

// This assumes it was called "something.doc"

string newfilename = folder_to_save_in + FileUpload1.FileName.Replace(".doc", ".html");

object o_newfilename = newfilename;

object o_format = Word.WdSaveFormat.wdFormatHTML;

object o_encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;

object o_endings = Word.WdLineEndingType.wdCRLF;

// Once again, we leave many of the parameters blank.

// See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbawd11/html/womthSaveAs1_HV05213080.asp

// for full list of parameters.

wordApplication.ActiveDocument.SaveAs(ref o_newfilename, ref o_format, ref o_nullobject,

ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject,

ref o_nullobject, ref o_nullobject, ref o_encoding, ref o_nullobject,

ref o_nullobject, ref o_endings, ref o_nullobject);

// Report success...

Label1.Text = "Uploaded successfully!";

// Finally, close original...

doc.Close(ref o_nullobject, ref o_nullobject, ref o_nullobject);

}

}http://www.wherecanibuyit.co.uk/ASP/converting_word_doc_files_to_html.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/秋刀鱼在做梦/article/detail/750068
推荐阅读
相关标签
  

闽ICP备14008679号