在后台word转为html后如何把一些标签加入html中啊
我现在转为html后想读html的流都是提示文件被另一程序使用,无法访问,请问还有别的方法吗string filePath="1.doc";
string htmlPath ="1.html";
try
{ Microsoft.Office.Interop.Word.ApplicationClass word = new Microsoft.Office.Interop.Word.ApplicationClass();
Type wordType = word.GetType();
Microsoft.Office.Interop.Word.Documents docs = word.Documents;
// 打开文件
Type docsType = docs.GetType();
object fileName = filePath;
Microsoft.Office.Interop.Word.Document doc = (Microsoft.Office.Interop.Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { fileName, true, true }); // 转换格式,另存为
Type docType = doc.GetType();
object saveFileName = htmlPath;
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML });
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
}
catch (Exception ex)
{
throw (ex);
}
finally
{
System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcessesByName("WINWORD"); foreach (System.Diagnostics.Process myProcess in myProcesses)
{
myProcess.Kill();
}
}
System.IO.StreamReader sr = new System.IO.StreamReader(htmlPath, System.Text.Encoding.Default);//这行报错,该文件被另一进程访问
{
我现在转为html后想读html的流都是提示文件被另一程序使用,无法访问,请问还有别的方法吗string filePath="1.doc";
string htmlPath ="1.html";
try
{ Microsoft.Office.Interop.Word.ApplicationClass word = new Microsoft.Office.Interop.Word.ApplicationClass();
Type wordType = word.GetType();
Microsoft.Office.Interop.Word.Documents docs = word.Documents;
// 打开文件
Type docsType = docs.GetType();
object fileName = filePath;
Microsoft.Office.Interop.Word.Document doc = (Microsoft.Office.Interop.Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { fileName, true, true }); // 转换格式,另存为
Type docType = doc.GetType();
object saveFileName = htmlPath;
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML });
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
}
catch (Exception ex)
{
throw (ex);
}
finally
{
System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcessesByName("WINWORD"); foreach (System.Diagnostics.Process myProcess in myProcesses)
{
myProcess.Kill();
}
}
System.IO.StreamReader sr = new System.IO.StreamReader(htmlPath, System.Text.Encoding.Default);//这行报错,该文件被另一进程访问
{
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货