1
A
回答
1
嘗試使用Office互操作
private void _convetHTML2Doc(string FileNameUpload)
{
string filePath = Server.MapPath("~/htmlfile");
object missing = Type.Missing;
object FileName = @"D:\" + "\\" + FileNameUpload;
object readOnly = true;
m_word = new Application();
m_word.Documents.Open(ref FileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
string newfilename = filePath + "\\" + FileNameUpload.Replace(".html", ".doc");
object o_newfilename = newfilename;
object o_encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
object o_format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;
object o_endings = Microsoft.Office.Interop.Word.WdLineEndingType.wdCRLF;
m_word.ActiveDocument.SaveAs(ref o_newfilename, ref o_format, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref o_encoding, ref missing, ref missing, ref o_endings, ref missing);
m_word.Quit(ref missing, ref missing, ref missing);
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_word);
}
1
MS警告不要當它沒有被觀看/監督/由最終用戶控制,例如自動運行Word因爲它可能會彈出一個消息框;所以如果你想在服務器上這樣做,那麼第三方組件可能比自動化Word更好。你也可以自己學習編寫Word文檔格式(這是一種記錄的XML格式),但是(學習和編寫該格式)可能比你想要的更麻煩。
此外,請注意,Word可以打開HTML:因此對於某些(可能略有)範圍,HTML已經是一個Word文檔。
相關問題
- 1. 從XML轉換爲Microsoft Word Doc
- 2. 將.doc/docx轉換爲Html
- 3. 將html轉換爲word c#
- 4. 將pdf轉換爲word doc文件
- 5. 將html轉換爲java中的doc
- 6. 將Microsoft Word轉換爲PHP腳本中的HTML
- 7. WPF或C#將Html轉換爲Doc
- 8. 使用Apache POI將Word轉換爲HTML
- 9. 如何在.net中將doc轉換爲jpg
- 10. 將.doc轉換爲HTML錯誤
- 11. 將doc/docx轉換爲語義HTML
- 12. 將HTML轉換爲doc(x)和/或PDF
- 13. 將HTML轉換爲odt,doc,docx
- 14. 使用Python將.doc轉換爲.html
- 15. CSS 2.1兼容HTML到Microsoft Word轉換?
- 16. 如何將html轉換爲php中的doc
- 17. C#將.doc轉換爲.htm
- 18. 將XML轉換爲HTML中的.net
- 19. 使用AWS上的Python將MS Word(.doc和.docx)文件轉換爲HTML Lambda
- 20. 如何將前端生成的Tinymce HTML代碼轉換爲word文件[.doc]?
- 21. 將Microsoft Word文檔轉換爲C中的數組#
- 22. 如何將html頁面轉換爲.net 2.0中的docx
- 23. 將HTML轉換爲Word文檔
- 24. 將MS Word內容轉換爲HTML
- 25. 將word通訊轉換爲html
- 26. 如何將word選擇轉換爲html?
- 27. 。將HTML轉換爲word文檔
- 28. 使用phpword將html轉換爲word
- 29. 快速將Word文檔轉換爲HTML
- 30. 將HTML(tinyMCE)轉換爲WORD(.docx)
在服務器上自動運行Office是一個_bad_想法。 – SLaks 2010-09-13 17:29:11
@SLaks:我不認爲OP說他們在服務器上這麼做... – 2010-09-13 20:52:30
@Otaku:答案是。 ('Server.MapPath') – SLaks 2010-09-13 23:18:14