你應該可以使用快遞版本。我修改了this question的答案。適應的代碼如下。您需要添加一個對Microsoft.Office.Interop.Word的引用才能工作。如果您缺少這個庫,請查看this article on MSDN。
看着WdSaveFormat你也可以將它保存爲格式過濾的HTML(wdFormatFilteredHTML)。
namespace Sample {
using Microsoft.Office.Interop.Word;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
class Program {
public static void Main()
{
Convert("C:\\Documents", WdSaveFormat.wdFormatHTML);
}
private static void Convert(string path, WdSaveFormat format)
{
DirectoryInfo dirInfo = new DirectoryInfo(path);
FileInfo[] wordFiles = dirInfo.GetFiles("*.doc");
if (wordFiles.Length == 0) {
return;
}
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
try {
word.Visible = false;
word.ScreenUpdating = false;
foreach (FileInfo wordFile in wordFiles) {
Object filename = (Object)wordFile.FullName;
Document doc = word.Documents.Open(ref filename, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
try {
doc.Activate();
object outputFileName = wordFile.FullName.Replace(".doc", ".html");
object fileFormat = format;
doc.SaveAs(ref outputFileName,
ref fileFormat, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
}
finally {
object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
((_Document)doc).Close(ref saveChanges, ref oMissing, ref oMissing);
doc = null;
}
}
}
finally {
((_Application)word).Quit(ref oMissing, ref oMissing, ref oMissing);
word = null;
}
}
}
}
它附帶辦公室。我想你可以參考VS2010 express – ivowiblo 2012-03-28 03:45:10
Express版本只是一個IDE限制,而不是一個CLR限制 – Seph 2012-03-28 06:02:26