Merge branch 'dev/stream' into dev/sense-detection

This commit is contained in:
LittleBoy 2025-01-02 16:09:06 +08:00
commit f1ddfa3d65
5 changed files with 94 additions and 34 deletions

View File

@ -338,7 +338,7 @@ namespace AIProofread
} }
else else
{ {
Thread.Sleep(3000); Thread.Sleep(500);
//FormMessage loadingDialog = null; //FormMessage loadingDialog = null;
//// 大于15W字符无法校对 //// 大于15W字符无法校对
//Task.Run(() => //Task.Run(() =>

View File

@ -627,8 +627,14 @@ namespace AIProofread.Model
if (marks.ContainsKey(item.Id)) continue; if (marks.ContainsKey(item.Id)) continue;
Logger.Log(string.Format("mark type {0} data {1}->{2}", item.Tag, item.Origin, item.Text)); Logger.Log(string.Format("mark type {0} data {1}->{2}", item.Tag, item.Origin, item.Text));
int _prev = prevOffset; int _prev = prevOffset;
bool isDisabled = false;
// 判断查找内容是否在原始数据中,否则直跳过
if(item.Tag != "i" )
{
isDisabled = correct.Insert.IndexOf(item.Origin) == -1;
}
// 查找对应区域并再该区域添加书签 // 查找对应区域并再该区域添加书签
var mark = DocumentUtil.FindRangeAndCreateBookmark(item, correct, CurrentDocument, ref prevOffset); var mark = isDisabled ? null : DocumentUtil.FindRangeAndCreateBookmark(item, correct, CurrentDocument, ref prevOffset);
// 防止调用方法中没有更新 // 防止调用方法中没有更新
if (_prev >= prevOffset) if (_prev >= prevOffset)
{ {

View File

@ -1,5 +1,6 @@
using Microsoft.Office.Interop.Word; using Microsoft.Office.Interop.Word;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
using UtilLib; using UtilLib;
namespace AIProofread.Model namespace AIProofread.Model
@ -11,6 +12,8 @@ namespace AIProofread.Model
public string OriginSentence { get; set; } public string OriginSentence { get; set; }
public CorrectItem Item { get; set; } public CorrectItem Item { get; set; }
private static readonly int MAX_WORD_LENGTH = 5;
public ExportDataItem(CorrectItem item, int pageNumber, int lineNumber,string originSentence = "") public ExportDataItem(CorrectItem item, int pageNumber, int lineNumber,string originSentence = "")
{ {
Item = item; Item = item;
@ -19,6 +22,27 @@ namespace AIProofread.Model
OriginSentence = originSentence; OriginSentence = originSentence;
} }
public static string GetSentence(ProofreadItem item)
{
var sentence = item.OriginSentence;
if (sentence.Length <= MAX_WORD_LENGTH)
{
return sentence;
}
var range = item.mark.Range;
// 获取range所在句子
//var first = range.Sentences.First.Start;
//var last = range.Sentences.Last.End;
var sentences = range.Sentences;
var sb = new StringBuilder();
foreach (Microsoft.Office.Interop.Word.Range s in sentences)
{
sb.Append(s.Text);
}
return sb.ToString().Trim();
}
public static List<ExportDataItem> GetExportData(Dictionary<int, ProofreadItem> marks) public static List<ExportDataItem> GetExportData(Dictionary<int, ProofreadItem> marks)
{ {
List<ExportDataItem> list = new List<ExportDataItem>(); List<ExportDataItem> list = new List<ExportDataItem>();
@ -37,7 +61,7 @@ namespace AIProofread.Model
var pageNumber = range.get_Information(WdInformation.wdActiveEndPageNumber); var pageNumber = range.get_Information(WdInformation.wdActiveEndPageNumber);
// 获取书签在当前页面的行数 // 获取书签在当前页面的行数
var lineNumber = range.get_Information(WdInformation.wdFirstCharacterLineNumber); var lineNumber = range.get_Information(WdInformation.wdFirstCharacterLineNumber);
list.Add(new ExportDataItem(it, pageNumber, lineNumber,item.Value.OriginSentence)); list.Add(new ExportDataItem(it, pageNumber, lineNumber,GetSentence(item.Value)));
} }
// 根据页码和行数排序 // 根据页码和行数排序
list.Sort((x, y) => list.Sort((x, y) =>

View File

@ -19,6 +19,8 @@ using System.Linq;
using NPOI.SS.Formula.Functions; using NPOI.SS.Formula.Functions;
using AIProofread.Model; using AIProofread.Model;
using System.Xml.Linq; using System.Xml.Linq;
using NPOI.SS.Util;
using NPOI.HSSF.Util;
namespace AIProofread namespace AIProofread
{ {
@ -559,14 +561,15 @@ namespace AIProofread
} }
ProcessExport(sfd.FileName); ProcessExport(sfd.FileName);
} }
catch (Exception) catch (Exception e)
{ {
Logger.Log(e);
Globals.ThisAddIn.ShowDialog("导出勘误表失败,请重试", null, null); Globals.ThisAddIn.ShowDialog("导出勘误表失败,请重试", null, null);
} }
} }
private static NPOI.SS.UserModel.ICell CreateCell(IRow row, int colIndex, IFont font, string text) private static NPOI.SS.UserModel.ICell CreateCell(IRow row, int colIndex, IFont font, string text,ICellStyle style = null)
{ {
var cell = row.CreateCell(colIndex); var cell = row.CreateCell(colIndex);
if (font != null) if (font != null)
@ -579,7 +582,15 @@ namespace AIProofread
{ {
cell.SetCellValue(text); cell.SetCellValue(text);
} }
if(style != null)
{
cell.CellStyle = style;
}
else
{
cell.CellStyle.WrapText = true; cell.CellStyle.WrapText = true;
}
return cell; return cell;
} }
@ -593,6 +604,7 @@ namespace AIProofread
simHeiFont.Color = NPOI.HSSF.Util.HSSFColor.Black.Index; simHeiFont.Color = NPOI.HSSF.Util.HSSFColor.Black.Index;
// 设置表格样式 // 设置表格样式
var style = CreateBaseCellStyle(book); var style = CreateBaseCellStyle(book);
style.FillPattern = FillPattern.NoFill; // SolidForeground
/* 系统与正文用不同字体区分(包括顶部栏、处理列、新增、删除等提示)勘误表系统字体为黑体,所有字号统一 */ /* 系统与正文用不同字体区分(包括顶部栏、处理列、新增、删除等提示)勘误表系统字体为黑体,所有字号统一 */
style.SetFont(simHeiFont); style.SetFont(simHeiFont);
style.BorderBottom = NPOI.SS.UserModel.BorderStyle.None; style.BorderBottom = NPOI.SS.UserModel.BorderStyle.None;
@ -601,33 +613,50 @@ namespace AIProofread
style.BorderRight = NPOI.SS.UserModel.BorderStyle.None; style.BorderRight = NPOI.SS.UserModel.BorderStyle.None;
style.WrapText = true; style.WrapText = true;
sheet.SetDefaultColumnStyle(0, style); // 设置宽度
sheet.SetDefaultColumnStyle(1, style); sheet.SetColumnWidth(0, 1); // 序号
sheet.SetDefaultColumnStyle(2, style); sheet.SetColumnHidden(0, true); // 隐藏序号
sheet.SetDefaultColumnStyle(3, style); sheet.SetColumnWidth(3, 80 * 256); // 详细信息
sheet.SetDefaultColumnStyle(4, style); sheet.SetColumnWidth(4, 20 * 256); // 异常
sheet.SetDefaultColumnStyle(5, style); sheet.SetColumnWidth(5, 20 * 256); // 建议
sheet.SetDefaultColumnStyle(6, style); sheet.SetColumnWidth(6, 10 * 256); // 处理状态
string[] headerTitles =
{
"序号","页","行","详细信息","异常", "建议","处理状态"
};
// 设置表头筛选及冻结 2.0.5 2024-12-30修改
sheet.CreateFreezePane(0, 1,0,1);
sheet.SetAutoFilter(CellRangeAddress.ValueOf("A1:G1"));
// 设置表头为白色
var headerStyle = book.CreateCellStyle();
var headerFont = book.CreateFont();
headerFont.FontName = "黑体"; // 设置字体
headerFont.FontHeightInPoints = 11; // 字体大小
var themeColor = new XSSFColor(new byte[] { 214, 170, 105 }); // 首行背景色黑色,字体用主题金色
((XSSFFont)headerFont).SetColor(themeColor);
headerStyle.SetFont(headerFont); // 应用字体
// 设置背景颜色为黑色
headerStyle.FillForegroundColor = HSSFColor.Black.Index; // 设置前景色
headerStyle.FillPattern = FillPattern.SolidForeground; // 使用实心填充模式
// 对齐方式
headerStyle.VerticalAlignment = VerticalAlignment.Center; // 垂直居中
headerStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; // 水平居中
// 表头设置 // 表头设置
var row = sheet.CreateRow(0); var row = sheet.CreateRow(0);
CreateCell(row, 0, simHeiFont, "序号"); row.Height = 40 * 20; // 首行加高
CreateCell(row, 1, simHeiFont, "页"); for (int i = 0; i < 7; i++)
CreateCell(row, 2, simHeiFont, "行"); {
CreateCell(row, 3, simHeiFont, "详细信息"); sheet.SetDefaultColumnStyle(i, style);
CreateCell(row, 4, simHeiFont, "异常"); var cell = CreateCell(row, i, headerFont, headerTitles[i], headerStyle);
CreateCell(row, 5, simHeiFont, "建议"); }
CreateCell(row, 6, simHeiFont, "处理状态");
// 设置宽度
sheet.SetColumnWidth(3, 80 * 256); // 详细信息
sheet.SetColumnWidth(4, 15 * 256); // 异常
sheet.SetColumnWidth(5, 15 * 256); // 建议
sheet.SetColumnWidth(6, 8 * 256); // 建议
var blackFont = CreateBaseFont(book, NPOI.HSSF.Util.HSSFColor.Black.Index); var blackFont = CreateBaseFont(book, NPOI.HSSF.Util.HSSFColor.Black.Index);
var redFont = CreateBaseFont(book, NPOI.HSSF.Util.HSSFColor.Red.Index); var redFont = CreateBaseFont(book, NPOI.HSSF.Util.HSSFColor.Red.Index);
// 获取排序后的数据 // 获取排序后的数据
@ -780,7 +809,7 @@ namespace AIProofread
// 保存到文件 // 保存到文件
book.Write(fs); book.Write(fs);
//Globals.ThisAddIn.ShowMessage("导出成功", 3000); //Globals.ThisAddIn.ShowMessage("导出成功", 3000);
Globals.ThisAddIn.ActiveDocument?.ShowMessage("导出勘误表成功", 3000, false); Globals.ThisAddIn.ActiveDocument?.ShowMessage("导出勘误表成功", 2000, false);
} }
} }

View File

@ -1,5 +1,6 @@
using Microsoft.Office.Interop.Word; using Microsoft.Office.Interop.Word;
using Newtonsoft.Json; using Newtonsoft.Json;
using NPOI.POIFS.FileSystem;
using NPOI.XWPF.UserModel; using NPOI.XWPF.UserModel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -23,11 +24,11 @@ namespace AIProofread
{ {
string ext = doc.FullName.ToLower(); string ext = doc.FullName.ToLower();
// 如果是 // 如果是
if (ext.EndsWith(".wps") || doc.Paragraphs.Count < 200 || doc.Tables.Count < 20) //if (ext.EndsWith(".wps") || doc.Paragraphs.Count < 200 || doc.Tables.Count < 20)
{ //{
// 如果段落数小于200或表格小于20 则直接使用vsto 获取数据 // // 如果段落数小于200或表格小于20 则直接使用vsto 获取数据
return GetAllTextByVSTO(doc); // return GetAllTextByVSTO(doc);
} //}
// 创建临时文件 方便数据读取 // 创建临时文件 方便数据读取
string docPath = Tools.GetReadDocumentFilePath(doc); string docPath = Tools.GetReadDocumentFilePath(doc);
@ -58,7 +59,7 @@ namespace AIProofread
{ {
foreach (var pc in cell.Paragraphs) foreach (var pc in cell.Paragraphs)
{ {
//list.Add(pc.ParagraphText); list.Add(new DocumentText(pc.ParagraphText.Replace("\u0002", ""), paragraphNumber));
paragraphNumber++; paragraphNumber++;
} }
} }