救急(C#操作Word转htm乱码问题)
zskyc 2010-04-21 08:51:36 public bool DocConvertToHtm(string path)
{
object file = path + ".doc";
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
object saveType = Word.WdSaveFormat.wdFormatHTML;
Word.ApplicationClass oWordApp = new Word.ApplicationClass();
try
{
Word.Document oWordDoc = oWordApp.Documents.Open(ref file, ref missing,ref readOnly,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref isVisible,ref missing,ref missing,ref missing,ref missing);
object saveFileName = path + ".htm";
oWordDoc.SaveAs(ref saveFileName,ref saveType,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,ref missing);
oWordDoc.Close(ref missing,ref missing,ref missing);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oWordDoc);
oWordDoc = null;
oWordApp.Application.Quit(ref missing, ref missing, ref missing);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oWordApp);
oWordApp = null;
return true;
}
catch(Exception ex)
{
oWordApp.Application.Quit(ref missing, ref missing, ref missing);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oWordApp);
oWordApp = null;
return false;
}
}
我的代码是这样,以前一直没问题,转换正常。是Vs2003+office2003。
现在是word上传到服务器上转换后的htm打开全乱码,不知为何。请高手指点。个人猜测是服务器出现问题,可是找了半天,找不出问题所在,服务器权限设置没问题。