perf: 📜️更新版本;对于特殊内容文档兼容
This commit is contained in:
parent
2b3e330841
commit
200f415ac6
Binary file not shown.
@ -427,7 +427,7 @@ namespace AIProofread
|
|||||||
{
|
{
|
||||||
Logger.Log(ex);
|
Logger.Log(ex);
|
||||||
data["code"] = 5;
|
data["code"] = 5;
|
||||||
data["message"] = "文档格式有误,请另存文档后再进行校对";
|
data["message"] = "文档格式有误或内容异常,请另存文档后再进行校对";
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -36,7 +36,7 @@ namespace AIProofread
|
|||||||
public class Config
|
public class Config
|
||||||
{
|
{
|
||||||
public static readonly string APP_NAME = "AI校对王";
|
public static readonly string APP_NAME = "AI校对王";
|
||||||
public static readonly string APP_VERSION = "2.2.2";
|
public static readonly string APP_VERSION = "2.2.3";
|
||||||
public static bool IS_WPS = false;
|
public static bool IS_WPS = false;
|
||||||
public static bool UpgradeForcedNotice = false;
|
public static bool UpgradeForcedNotice = false;
|
||||||
public static readonly string APP_BASE_DIR = AppDomain.CurrentDomain.BaseDirectory;
|
public static readonly string APP_BASE_DIR = AppDomain.CurrentDomain.BaseDirectory;
|
||||||
|
@ -7,10 +7,10 @@ using System.Security;
|
|||||||
// 控制。更改这些特性值可修改
|
// 控制。更改这些特性值可修改
|
||||||
// 与程序集关联的信息。
|
// 与程序集关联的信息。
|
||||||
[assembly: AssemblyTitle("AI校对王")]
|
[assembly: AssemblyTitle("AI校对王")]
|
||||||
[assembly: AssemblyDescription("AI校对王 2.2.1")]
|
[assembly: AssemblyDescription("AI校对王 2.2.3")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("果麦文化传媒股份有限公司")]
|
[assembly: AssemblyCompany("果麦文化传媒股份有限公司")]
|
||||||
[assembly: AssemblyProduct("AI校对王 2.2.1")]
|
[assembly: AssemblyProduct("AI校对王 2.2.3")]
|
||||||
[assembly: AssemblyCopyright("Copyright © 果麦文化传媒股份有限公司 2025")]
|
[assembly: AssemblyCopyright("Copyright © 果麦文化传媒股份有限公司 2025")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
@ -34,5 +34,5 @@ using System.Security;
|
|||||||
// 方法是按如下所示使用“*”: :
|
// 方法是按如下所示使用“*”: :
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("2.0")]
|
[assembly: AssemblyVersion("2.0")]
|
||||||
[assembly: AssemblyFileVersion("2.2.1.0")]
|
[assembly: AssemblyFileVersion("2.2.3.0")]
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
@ -41,22 +42,34 @@ namespace AIProofread
|
|||||||
List<DocumentText> list = new List<DocumentText>();
|
List<DocumentText> list = new List<DocumentText>();
|
||||||
|
|
||||||
//DocumentReader.ReadByVSTO(doc, Globals.ThisAddIn.Application, list);
|
//DocumentReader.ReadByVSTO(doc, Globals.ThisAddIn.Application, list);
|
||||||
using (FileStream stream = new FileStream(docPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
try
|
||||||
{
|
{
|
||||||
ReadTextByNPOI(stream, list);
|
ReadTextByNPOI(docPath, list);
|
||||||
//try
|
}
|
||||||
|
catch (POIXMLException ex)
|
||||||
|
{
|
||||||
|
// 编号有误,移除编号再读取
|
||||||
|
if (ex.StackTrace.Contains("NPOI.XWPF.UserModel.XWPFNumbering"))
|
||||||
|
{
|
||||||
|
RemoveNumbersReadTextByNPOI(docPath, list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//using (FileStream stream = new FileStream(docPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||||
//{
|
//{
|
||||||
|
|
||||||
|
// //try
|
||||||
|
// //{
|
||||||
|
|
||||||
|
// //}
|
||||||
|
// //catch (POIXMLException npoiError)
|
||||||
|
// //{
|
||||||
|
// // Logger.Log("GetAllText Error", npoiError);
|
||||||
|
// // // Logger.Log("GetAllText", e);
|
||||||
|
// // // return GetAllTextByVSTO(doc);
|
||||||
|
// // // 读取文档
|
||||||
|
// // DocumentReader.ReadByVSTO(doc, Globals.ThisAddIn.Application, list);
|
||||||
|
// //}
|
||||||
//}
|
//}
|
||||||
//catch (POIXMLException npoiError)
|
|
||||||
//{
|
|
||||||
// Logger.Log("GetAllText Error", npoiError);
|
|
||||||
// // Logger.Log("GetAllText", e);
|
|
||||||
// // return GetAllTextByVSTO(doc);
|
|
||||||
// // 读取文档
|
|
||||||
// DocumentReader.ReadByVSTO(doc, Globals.ThisAddIn.Application, list);
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
var map = new Dictionary<string, object>
|
var map = new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{ "list", list },
|
{ "list", list },
|
||||||
@ -67,7 +80,24 @@ namespace AIProofread
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ReadTextByNPOI(FileStream stream, List<DocumentText> list)
|
private static void RemoveNumbersReadTextByNPOI(string filePath, List<DocumentText> list)
|
||||||
|
{
|
||||||
|
list.Clear();
|
||||||
|
var fs = File.OpenWrite(filePath);
|
||||||
|
// 打开Zip文件,删除 numbering.xml
|
||||||
|
using (ZipArchive archive = new ZipArchive(fs, ZipArchiveMode.Update))
|
||||||
|
{
|
||||||
|
var numberingEntry = archive.GetEntry("word/numbering.xml");
|
||||||
|
numberingEntry?.Delete(); // 删除 numbering.xml
|
||||||
|
}
|
||||||
|
fs.Close();
|
||||||
|
ReadTextByNPOI(filePath, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ReadTextByNPOI(string filePath, List<DocumentText> list)
|
||||||
|
{
|
||||||
|
//, FileMode.Open, FileAccess.Read, FileShare.ReadWrite
|
||||||
|
using (var stream = File.OpenRead(filePath))
|
||||||
{
|
{
|
||||||
XWPFDocument ndoc = new XWPFDocument(stream);
|
XWPFDocument ndoc = new XWPFDocument(stream);
|
||||||
var paragraphs = ndoc.Paragraphs;
|
var paragraphs = ndoc.Paragraphs;
|
||||||
@ -79,7 +109,7 @@ namespace AIProofread
|
|||||||
{
|
{
|
||||||
// 处理普通段落
|
// 处理普通段落
|
||||||
var text = p.ParagraphText.Replace("\u0002", "");
|
var text = p.ParagraphText.Replace("\u0002", "");
|
||||||
if(text.Trim().Length > 0)
|
if (text.Trim().Length > 0)
|
||||||
{
|
{
|
||||||
list.Add(new DocumentText(text, paragraphNumber));
|
list.Add(new DocumentText(text, paragraphNumber));
|
||||||
}
|
}
|
||||||
@ -109,7 +139,7 @@ namespace AIProofread
|
|||||||
|
|
||||||
// 如果需要,可以进一步解析目录项// 例如,按换行符拆分目录内容
|
// 如果需要,可以进一步解析目录项// 例如,按换行符拆分目录内容
|
||||||
var tocEntries = tocText.Split(new string[] { "\n", "\r", "\r\n", "\f" }, StringSplitOptions.None);
|
var tocEntries = tocText.Split(new string[] { "\n", "\r", "\r\n", "\f" }, StringSplitOptions.None);
|
||||||
paragraphNumber+= tocEntries.Length;
|
paragraphNumber += tocEntries.Length;
|
||||||
// 暂时跳过目录
|
// 暂时跳过目录
|
||||||
//foreach (string entry in tocEntries)
|
//foreach (string entry in tocEntries)
|
||||||
//{
|
//{
|
||||||
@ -119,6 +149,7 @@ namespace AIProofread
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static string GetReadDocumentFilePath(Microsoft.Office.Interop.Word.Document doc)
|
public static string GetReadDocumentFilePath(Microsoft.Office.Interop.Word.Document doc)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user