如何使用ASP.NET& amp ;;将Microsoft Word doc文件转换为HTML文件? C#?
答案 0 :(得分:1)
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
答案 1 :(得分:1)
通过使用Microsoft.Office.Interop.Word命名空间,服务器需要安装Microsoft Word。我不想要的!
答案 2 :(得分:0)
使用Microsoft Word的内置功能 - “文件>另存为网页...”
或者,要以编程方式执行此操作,请使用_Document.SaveAs
method中的Microsoft.Office.Interop.Word
namespace。