|
@@ -8,6 +8,7 @@ using System.Text.RegularExpressions;
|
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
using Microsoft.Office.Interop.Word;
|
|
using Microsoft.Office.Interop.Word;
|
|
|
using wispro.sp.entity.CompareCase;
|
|
using wispro.sp.entity.CompareCase;
|
|
|
|
|
+using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace wispro.sp.utility
|
|
namespace wispro.sp.utility
|
|
@@ -63,18 +64,33 @@ namespace wispro.sp.utility
|
|
|
// 打开Word文档
|
|
// 打开Word文档
|
|
|
System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
|
|
System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
|
|
|
|
|
|
|
|
- if (fileInfo.Name.Contains("-保密-"))
|
|
|
|
|
|
|
+ if (fileInfo.Name.Contains("-保密-") || fileInfo.Name.Contains("加密版"))
|
|
|
{
|
|
{
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- doc = word.Documents.Open(fileInfo.FullName);
|
|
|
|
|
- // 读取文档内容
|
|
|
|
|
- content = doc.Content.Text;
|
|
|
|
|
-
|
|
|
|
|
- List<string> lines = content.Split(new string[] { "\f", "\r" }, StringSplitOptions.None).ToList();
|
|
|
|
|
- return List2String(lines);
|
|
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ doc = word.Documents.Open(
|
|
|
|
|
+ fileInfo.FullName,
|
|
|
|
|
+ ReadOnly: true,
|
|
|
|
|
+ PasswordDocument: Type.Missing,
|
|
|
|
|
+ WritePasswordDocument: "");
|
|
|
|
|
+ // 读取文档内容
|
|
|
|
|
+ content = doc.Content.Text;
|
|
|
|
|
+
|
|
|
|
|
+ List<string> lines = content.Split(new string[] { "\f", "\r" }, StringSplitOptions.None).ToList();
|
|
|
|
|
+ return List2String(lines);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (COMException ex) when (ex.ErrorCode == -2146823167 || ex.ErrorCode == -2147024891) // 0x80070005
|
|
|
|
|
+ {
|
|
|
|
|
+ return null; // 访问被拒绝 → 文档加密
|
|
|
|
|
+ }
|
|
|
|
|
+ catch
|
|
|
|
|
+ {
|
|
|
|
|
+ throw; // 其他异常(如文件损坏)需单独处理
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|