当前位置: 首页 > 编程语言 > C#

使用VisualStudio2010Express将.doc保存-转换为.htmlShare

时间:2023-04-10 17:17:50 C#

使用VisualStudio2010Express将.doc保存/转换为.html加工。我只有VisualStudio2010速成版。express版可以用吗?我找到了如何进行转换的示例,但它们需要Microsoft.Office.Tools.Word库,而Express并未提供该库。编辑:我找到了它,它实际上在COM对象中称为MicrosoftWord12.0对象库,它是Microsoft.Office.Interop.Word命名空间。您应该可以使用express版本来完成。我改编了这个问题的答案。改编后的代码如下。您需要添加对Microsoft.Office.Interop.Word的引用才能正常工作。如果您错过了这个库,请查看MSDN上的这篇文章。查看WdSaveFormat,您还可以将其保存为格式过滤HTML(wdFormatFilteredHTML)。以上就是C#学习教程:使用VisualStudio2010Express将.doc保存/转换成.html的全部内容分享给大家。如果对大家有用,需要进一步了解C#学习教程,希望大家多多关注—namespaceSample{usingMicrosoft.Office.Interop.Word;使用系统;使用System.Collections.Generic;使用System.IO;使用System.Linq;使用系统文本;类程序{publicstaticvoidMain(){Convert("C:\Documents",WdSaveFormat.wdFormatHTML);}privatestaticvoidConvert(stringpath,WdSaveFormatformat){DirectoryInfodirInfo=newDirectoryInfo(path);FileInfo[]wordFiles=dirInfo.GetFiles("*.doc");如果(wordFiles.Length==0){返回;}objectoMissing=System.Reflection.Missing.Value;Microsoft.Office.Interop.Word.Applicationword=newMicrosoft.Office.Interop.Word.Application();尝试{word.Visible=false;word.ScreenUpdating=false;foreach(FileInfowordFileinwordFiles){Objectfilename=(Object)wordFile.FullName;文档doc=word.Documents.Open(reffilename,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing);尝试{doc.Activate();objectoutputFileName=wordFile.FullName.Replace(".doc",".html");目标文件格式=格式;doc.SaveAs(参考输出文件名,参考文件格式,参考缺失,参考缺失,参考缺失,参考缺失,参考缺失,参考缺失,参考缺失,参考缺失,参考缺失,参考缺失,参考缺失,参考缺失,参考o缺失);}最后{objectsaveChanges=WdSaveOptions.wdDoNotSaveChanges;((_Document)doc).Close(refsaveChanges,refoMissing,ref);文档=空;}}}最后{((_Application)word).Quit(refoMissing,refoMissing,refoMissing);单词=空;}}}}本文收集自网络,不代表立场。如涉及侵权,请点击右边联系管理员删除。如需转载请注明出处: