C#打開並修復word實現方法
C#操作打開損壞的word時候,可以采用如何方法進行打開,如下:
objDocLast = objApp.Documents.Open(
ref objOrgDoc, //文件名
ref objMissing, //確認版本
ref objMissing, //只讀
ref objMissing, //添加到最近的文件
ref objMissing, //密碼文件
ref objMissing, //密碼摸板
ref objMissing, //回復
ref objMissing, //寫密碼文件
ref objMissing, //寫密碼摸板
ref objMissing, //格式
ref objMissing, //加密
ref objMissing, //可視
ref objMissing, //打開並修復
ref objMissing, //直接文黨
ref objMissing, //沒加密的對話框
ref objMissing //XML傳輸
);
#region - 打開並修復文檔 -
public static bool OpenAndRepair(string filePath, bool isVisible)
{
try
{
oWord = new Microsoft.Office.Interop.Word.Application();
oWord.Visible = isVisible;
object path = filePath;
oDoc = oWord.Documents.Open(ref path,
ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
ref Nothing, true, ref Nothing, ref Nothing, ref Nothing);
return true;
}
catch (Exception)
{
return false;
}
}
#endregion
摘自 love007