feat:勘误表导出底层组件修改

This commit is contained in:
LittleBoy 2025-04-13 01:32:21 +08:00
parent cf148e9000
commit fb2f5e0d16
18 changed files with 643 additions and 105 deletions

Binary file not shown.

View File

@ -128,6 +128,12 @@
<Reference Include="BouncyCastle.Cryptography, Version=2.0.0.0, Culture=neutral, PublicKeyToken=072edcf4a5328938, processorArchitecture=MSIL">
<HintPath>..\packages\BouncyCastle.Cryptography.2.3.1\lib\net461\BouncyCastle.Cryptography.dll</HintPath>
</Reference>
<Reference Include="DocumentFormat.OpenXml, Version=3.3.0.0, Culture=neutral, PublicKeyToken=8fb06cb64d019a17, processorArchitecture=MSIL">
<HintPath>..\packages\DocumentFormat.OpenXml.3.3.0\lib\net46\DocumentFormat.OpenXml.dll</HintPath>
</Reference>
<Reference Include="DocumentFormat.OpenXml.Framework, Version=3.3.0.0, Culture=neutral, PublicKeyToken=8fb06cb64d019a17, processorArchitecture=MSIL">
<HintPath>..\packages\DocumentFormat.OpenXml.Framework.3.3.0\lib\net46\DocumentFormat.OpenXml.Framework.dll</HintPath>
</Reference>
<Reference Include="Enums.NET, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7ea1c1650d506225, processorArchitecture=MSIL">
<HintPath>..\packages\Enums.NET.4.0.1\lib\net45\Enums.NET.dll</HintPath>
</Reference>
@ -140,8 +146,11 @@
<Reference Include="MathNet.Numerics, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cd8b63ad3d691a37, processorArchitecture=MSIL">
<HintPath>..\packages\MathNet.Numerics.Signed.5.0.0\lib\net461\MathNet.Numerics.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IO.RecyclableMemoryStream, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IO.RecyclableMemoryStream.3.0.0\lib\netstandard2.0\Microsoft.IO.RecyclableMemoryStream.dll</HintPath>
<Reference Include="Microsoft.IO.RecyclableMemoryStream, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IO.RecyclableMemoryStream.3.0.1\lib\netstandard2.0\Microsoft.IO.RecyclableMemoryStream.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Microsoft.Web.WebView2.Core, Version=1.0.2210.55, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.2210.55\lib\net45\Microsoft.Web.WebView2.Core.dll</HintPath>
@ -167,6 +176,7 @@
<Reference Include="NPOI.OpenXmlFormats, Version=2.7.1.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
<HintPath>..\packages\NPOI.2.7.1\lib\netstandard2.0\NPOI.OpenXmlFormats.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="SixLabors.Fonts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d998eea7b14cab13, processorArchitecture=MSIL">
<HintPath>..\packages\SixLabors.Fonts.1.0.1\lib\netstandard2.0\SixLabors.Fonts.dll</HintPath>
</Reference>
@ -177,6 +187,9 @@
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.Annotations, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.ComponentModel.Annotations.5.0.0\lib\net461\System.ComponentModel.Annotations.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" />
<Reference Include="System.Configuration.ConfigurationManager, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
@ -203,8 +216,8 @@
<Reference Include="System.Security.Cryptography.Pkcs, Version=6.0.0.3, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Cryptography.Pkcs.6.0.3\lib\net461\System.Security.Cryptography.Pkcs.dll</HintPath>
</Reference>
<Reference Include="System.Security.Cryptography.Xml, Version=6.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Cryptography.Xml.6.0.1\lib\net461\System.Security.Cryptography.Xml.dll</HintPath>
<Reference Include="System.Security.Cryptography.Xml, Version=8.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Cryptography.Xml.8.0.2\lib\net462\System.Security.Cryptography.Xml.dll</HintPath>
</Reference>
<Reference Include="System.Security.Permissions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Permissions.6.0.0\lib\net461\System.Security.Permissions.dll</HintPath>
@ -373,6 +386,7 @@
<Compile Include="core\CorrectionCharacter.cs" />
<Compile Include="core\CorrectionFragmentAbstract.cs" />
<Compile Include="core\CorrectionRangeAbstract.cs" />
<Compile Include="core\CorrectResultExportor.cs" />
<Compile Include="core\DocumentReader.cs" />
<Compile Include="core\DocumentText.cs" />
<Compile Include="core\DocumentUtil.cs" />

View File

@ -36,7 +36,7 @@ namespace AIProofread
public class Config
{
public static readonly string APP_NAME = "AI校对王";
public static readonly string APP_VERSION = "2.2.3";
public static readonly string APP_VERSION = "2.2.4";
public static bool IS_WPS = false;
public static bool UpgradeForcedNotice = false;
public static readonly string APP_BASE_DIR = AppDomain.CurrentDomain.BaseDirectory;

View File

@ -112,6 +112,11 @@ namespace AIProofread.Controls
this.FormBorderStyle = FormBorderStyle.None;
}
public void SetHeight(int height)
{
this.Height = height;
}
protected async void InitWebView(WebView2 webView,String url,string name,Action callaback = null)
{
//Bridge.InitWebEnvAsync(name, webView);

View File

@ -41,7 +41,7 @@
this.web.Dock = System.Windows.Forms.DockStyle.Fill;
this.web.Location = new System.Drawing.Point(0, 0);
this.web.Name = "web";
this.web.Size = new System.Drawing.Size(650, 500);
this.web.Size = new System.Drawing.Size(650, 400);
this.web.TabIndex = 0;
this.web.ZoomFactor = 1D;
//
@ -49,7 +49,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(650, 500);
this.ClientSize = new System.Drawing.Size(650, 400);
this.Controls.Add(this.web);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "FormLogin";

View File

@ -61,6 +61,5 @@ namespace AIProofread.Controls
InitWebView(web, Config.WebPath("login?action=" + this.action + "&version=" + Config.APP_VERSION + "&t=" + DateTime.Now.Ticks), "login");
}
}
}

View File

@ -32,38 +32,66 @@ namespace AIProofread.Model
{
return sentence;
}
// 截取中间位置
try
if (isInsert)
{
var middlePosition = MAX_WORD_LENGTH / 2;
var cutStart = item.content.Start - middlePosition;
// 越界了
if (cutStart < 0)
Debug.WriteLine("GetReadDocumentFilePath Start ==>", DateTime.Now.ToLongTimeString());
}
// 截取中间位置
if(sentence.Length > MAX_WORD_LENGTH)
{
try
{
cutStart = 0;
var middlePosition = MAX_WORD_LENGTH / 2;
var cutStart = item.content.Start - middlePosition;
// 越界了
if (cutStart < 0)
{
cutStart = 0;
}
var originText = sentence.Substring(cutStart, Math.Min(sentence.Length - cutStart, MAX_WORD_LENGTH));
if (!isInsert)
{
item.content.Start = item.content.Start - cutStart;
item.content.End = item.content.End - cutStart;
return originText;
}
}
var originText = sentence.Substring(cutStart, Math.Min(sentence.Length, MAX_WORD_LENGTH));
if (!isInsert)
catch (Exception ex)
{
item.content.Start = item.content.Start - cutStart;
item.content.End = item.content.End - cutStart;
return originText;
Logger.Log(ex);
}
}
catch (Exception ex) { Logger.Log(ex); }
var range = item.mark.Range;
var sb = new StringBuilder();
if (sentence.Length <= MAX_WORD_LENGTH && isInsert)
{
var before = item.content.Start == 0 ? string.Empty: sentence.Substring(0, item.content.Start);
var after = item.content.Start >= sentence.Length ? string.Empty : sentence.Substring(item.content.Start);
if (!string.IsNullOrEmpty(before))
{
sb.Append(before);
}
//
sb.Append(ToolUtil.GetBlankText(item.content.Text.Length, "˽"));
if (!string.IsNullOrEmpty(after))
{
sb.Append(after);
}
item.content.Start = item.content.Start;
item.content.End = item.content.Start + 1;
return sb.ToString().Trim();
}
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)
{
var str = s.Text;
if (isInsert && range.Start >= s.Start && range.End <= s.End)
{
sb.Append(str.Replace(" ", "˽"));
sb.Append(str.Replace(" ", "˽"));
}
else
{

View File

@ -75,6 +75,7 @@ namespace AIProofread
this.BtnTest = this.Factory.CreateRibbonButton();
this.BtnOpenAppDir = this.Factory.CreateRibbonButton();
this.BtnShowVersion = this.Factory.CreateRibbonButton();
this.button2 = this.Factory.CreateRibbonButton();
this.dropDown1 = this.Factory.CreateRibbonDropDown();
this.tabAIProofread.SuspendLayout();
this.group1.SuspendLayout();
@ -327,6 +328,7 @@ namespace AIProofread
this.grpDebug.Items.Add(this.BtnTest);
this.grpDebug.Items.Add(this.BtnOpenAppDir);
this.grpDebug.Items.Add(this.BtnShowVersion);
this.grpDebug.Items.Add(this.button2);
this.grpDebug.Items.Add(this.dropDown1);
this.grpDebug.Label = "开发调试";
this.grpDebug.Name = "grpDebug";
@ -380,6 +382,12 @@ namespace AIProofread
this.BtnShowVersion.Name = "BtnShowVersion";
this.BtnShowVersion.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.BtnShowVersion_Click);
//
// button2
//
this.button2.Label = "打开登录窗口";
this.button2.Name = "button2";
this.button2.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.button2_Click);
//
// dropDown1
//
ribbonDropDownItemImpl1.Label = "开发";
@ -452,6 +460,7 @@ namespace AIProofread
internal Microsoft.Office.Tools.Ribbon.RibbonMenu menuProofreadList;
internal Microsoft.Office.Tools.Ribbon.RibbonButton BtnProofreadExact;
internal Microsoft.Office.Tools.Ribbon.RibbonButton BtnProofreadFull;
internal Microsoft.Office.Tools.Ribbon.RibbonButton button2;
}
partial class ThisRibbonCollection

View File

@ -639,5 +639,10 @@ namespace AIProofread
Globals.ThisAddIn.ActiveDocument.CheckPanel();
Globals.ThisAddIn.SendMessageToWeb("start", "full");
}
private void button2_Click(object sender, RibbonControlEventArgs e)
{
Bridge.bridge.ShowLoginForm(null);
}
}
}

View File

@ -225,6 +225,9 @@
<metadata name="BtnShowVersion.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="button2.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="dropDown1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>

View File

@ -8,12 +8,9 @@ using AIProofread.Controls;
using UtilLib;
using AIProofread.Model;
using System.Collections.Generic;
using Excel = Microsoft.Office.Interop.Excel;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Text;
//using CustomTaskPane = Microsoft.Office.Core.CustomTaskPane;
//using CustomTaskPane = Microsoft.Office.Tools.CustomTaskPane;
//using NPOI.SS.Formula.Functions;
namespace AIProofread
{
@ -565,8 +562,6 @@ namespace AIProofread
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// PanelModule.DisposeCTP();
//this.proofreadPanel.Dispose();
// 取消捕获全局异常事件
AppDomain.CurrentDomain.UnhandledException -= ProcessApplicationException;
System.Windows.Forms.Application.ThreadException -= ProcessApplicationFormException;

View File

@ -12,7 +12,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Security.Cryptography.Xml" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.1" newVersion="6.0.0.1" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.2" newVersion="8.0.0.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
@ -22,6 +22,10 @@
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.IO.RecyclableMemoryStream" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -0,0 +1,513 @@
using AIProofread.Model;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using DocumentFormat.OpenXml;
using System.Windows.Forms;
using UtilLib;
using System.Diagnostics;
using System;
namespace AIProofread.core
{
public class CorrectResultExportor
{
// 设置表头
private static readonly string[] HeaderCols =
{
"序号","页","行","详细信息","异常", "建议","处理状态"
};
private static CorrectResultExportor exportor = new CorrectResultExportor();
private HexBinaryValue primaryColor = new HexBinaryValue("D6AA69");
private HexBinaryValue whiteColor = new HexBinaryValue("FFFFFF");
private HexBinaryValue blackColor = new HexBinaryValue("000000");
private CorrectResultExportor()
{
}
public static CorrectResultExportor GetInstance()
{
return exportor;
}
private Stylesheet CreateStyleSheet()
{
// 字体样式(默认和微软雅黑)
Fonts fonts = new Fonts(
new Font( // 默认字体
new FontName() { Val = "宋体" },
new FontSize() { Val = 11 }
),
new Font( // 微软雅黑字体
new FontName() { Val = "黑体" },
new RunFont() { Val = "黑体" },
new FontSize() { Val = 11 }
),
new Font( // 首行表头
new FontName() { Val = "黑体" },
new RunFont() { Val = "黑体" },
new FontSize() { Val = 11 },
new Color() { Rgb = primaryColor } // 字体颜色
),
new Font( // 首行表头
new FontName() { Val = "宋体" },
new RunFont() { Val = "宋体" },
new FontSize() { Val = 11 }
)
);
// 背景填充(黑色/金色)
Fills fills = new Fills(
new Fill(new PatternFill() { PatternType = PatternValues.None }),
new Fill(new PatternFill()
{
PatternType = PatternValues.Solid,
ForegroundColor = new ForegroundColor() { Rgb = blackColor }
}),
new Fill(new PatternFill()
{
PatternType = PatternValues.Solid,
ForegroundColor = new ForegroundColor() { Rgb = blackColor }
})
);
// 边框样式
Borders borders = new Borders(
new Border(), // 默认无边框
new Border(
new LeftBorder() { Style = BorderStyleValues.Thin, Color = new Color() { Rgb = blackColor } },
new RightBorder() { Style = BorderStyleValues.Thin, Color = new Color() { Rgb = blackColor } },
new TopBorder() { Style = BorderStyleValues.Thin, Color = new Color() { Rgb = blackColor } },
new BottomBorder() { Style = BorderStyleValues.Thin, Color = new Color() { Rgb = blackColor } },
new DiagonalBorder()
)
);
// 单元格样式
CellFormats cellFormats = new CellFormats(
new CellFormat() // 默认
{
ApplyAlignment = true,
Alignment = new Alignment()
{
Horizontal = HorizontalAlignmentValues.Left,
Vertical = VerticalAlignmentValues.Center,
WrapText = true
}
},
new CellFormat() // 首行
{
FontId = 2, // 使用黑体字体
FillId = 2, // 使用黑色背景
ApplyFont = true,
ApplyFill = true,
ApplyAlignment = true,
Alignment = new Alignment()
{
Horizontal = HorizontalAlignmentValues.Center,
Vertical = VerticalAlignmentValues.Center,
WrapText = true
}
},
new CellFormat() // 单纯的黑体
{
FontId = 1,
ApplyFont = true,
ApplyAlignment = true,
Alignment = new Alignment()
{
Horizontal = HorizontalAlignmentValues.Center,
Vertical = VerticalAlignmentValues.Center,
WrapText = true
}
},
new CellFormat() // 单纯的黑体
{
FontId = 3,
ApplyFont = true,
Alignment = new Alignment()
{
Horizontal = HorizontalAlignmentValues.Left,
Vertical = VerticalAlignmentValues.Center,
WrapText = true
}
}
);
return new Stylesheet(fonts, fills, borders, cellFormats);
}
/// <summary>
/// 使用Excel COM导出
/// </summary>
/// <param name="fileName"></param>
public void ExportResult(string fileName)
{
// 创建计时器,用于计算运行时间
var stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
// 获取要导出的数据
var exportDataItems = ExportDataItem.GetExportData(Globals.ThisAddIn.ActiveDocument.marks);
// 创建Excel对象
using (SpreadsheetDocument document = SpreadsheetDocument.Create(fileName, SpreadsheetDocumentType.Workbook))
{
#region Workbook Worksheet
WorkbookPart workbookPart = document.AddWorkbookPart();
// 设置样式
var stylesPart = workbookPart.AddNewPart<WorkbookStylesPart>();
stylesPart.Stylesheet = CreateStyleSheet();
stylesPart.Stylesheet.Save();
// 创建工作簿
workbookPart.Workbook = new Workbook();
WorksheetPart worksheetPart = workbookPart.AddNewPart<WorksheetPart>();
var worksheet = new Worksheet(new SheetData());
// 冻结首行
worksheet.Append(new SheetViews(
new SheetView()
{
WorkbookViewId = 0,
Pane = new Pane()
{
VerticalSplit = 1,
TopLeftCell = "A2",
ActivePane = PaneValues.BottomLeft,
State = PaneStateValues.Frozen
}
}
));
worksheetPart.Worksheet = worksheet;
// 创建
Sheets sheets = document.WorkbookPart.Workbook.AppendChild(new Sheets());
Sheet sheet = new Sheet()
{
Id = document.WorkbookPart.GetIdOfPart(worksheetPart),
SheetId = 1,
Name = "Sheet1"
};
sheets.Append(sheet);
#endregion
// 获取 SheetData
SheetData sheetData = worksheetPart.Worksheet.GetFirstChild<SheetData>();
// 创建表头
CreateHeader(sheetData);
int rowIndex = 1;
foreach (var item in exportDataItems)
{
// 创建行
try
{
CreateRow(sheetData, item, ref rowIndex);
}catch(Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
// 美化sheet
StyleSheet(worksheetPart);
// 筛选
worksheetPart.Worksheet.Append(new AutoFilter { Reference = "A1:G1" });
//sheet.Append(new AutoFilter() { Reference = "A1:G1"});
}
#region
//var headerRange = worksheet.Range["A1:G1"];
//var allRange = worksheet.Range["A1:G" + rowIndex];
//// 对齐方式
//// 所有都是垂直居中
//allRange.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
//// 水平居中
//headerRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
//worksheet.Columns["A:C"].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
//worksheet.Columns["G"].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
//// 全局样式
//allRange.Font.Size = 11;
//worksheet.Rows[1].RowHeight = 40;
//// 设置自动换行
//worksheet.Rows.WrapText = true;
//var themeColor = new XSSFColor(new byte[] { 214, 170, 105 }); // 首行背景色黑色,字体用主题金色
//// 设置背景/颜色
//headerRange.Font.Color = ColorTranslator.ToOle(Color.FromArgb(255, 214, 170, 105));
//headerRange.Interior.Pattern = Excel.XlPattern.xlPatternSolid;
//headerRange.Interior.Color = ColorTranslator.ToOle(Color.Black);
//// 设置字体
//worksheet.Rows[1].Font.Name = "黑体";
//worksheet.Columns["G"].Font.Name = "黑体";
// 设置列宽
//worksheet.Columns["A:C"].ColumnWidth = 10;
//worksheet.Columns["D"].ColumnWidth = 80;
//worksheet.Columns["E:F"].ColumnWidth = 20;
//worksheet.Columns["G"].ColumnWidth = 10;
// 设置冻结、筛选
//worksheet.Activate();
//worksheet.Range["B1"].Select(); // 必须选择冻结点
// // 冻结第一行
//excel.ActiveWindow.SplitRow = 1;
//excel.ActiveWindow.FreezePanes = true;
//worksheet.EnableAutoFilter = true;
//// 设置第一行筛选
////int lastRow = worksheet.UsedRange.Rows.Count;
//Excel.Range range = worksheet.get_Range("A1", "D1");
//range.AutoFilter("1", "<>", Excel.XlAutoFilterOperator.xlOr, "", true);
#endregion
stopwatch.Stop();
MessageBox.Show("导出完成,运行时间:" + stopwatch.Elapsed.TotalMilliseconds + "毫秒");
}
private void StyleSheet(WorksheetPart worksheetPart)
{
// 设置列宽
Columns columns = new Columns();
SetColumnWidth(1, 3, 6, columns);
SetColumnWidth(4, 80, columns);
SetColumnWidth(5, 6, 20, columns);
SetColumnWidth(7, 10, columns);
worksheetPart.Worksheet.InsertAt(columns, 1);
}
private void SetColumnWidth(uint colIndex, int width, Columns columns)
{
SetColumnWidth(colIndex, colIndex, width, columns);
}
private void SetColumnWidth(uint startColIndex, uint endColIndex, int width, Columns columns)
{
columns.Append(
new Column()
{
Min = startColIndex, // 从第1列开始
Max = endColIndex, // 到第3列结束
Width = width, // 宽度值(一般 8.43 为默认)
CustomWidth = true
}
);
}
private void CreateHeader(SheetData sheetData)
{
// 创建表头行
Row headerRow = new Row() { Height = 40, CustomHeight = true };
foreach (var header in HeaderCols)
{
headerRow.AppendChild(new Cell()
{
DataType = CellValues.String,
StyleIndex = 1, // 设置背景为黑色,字体为金色
CellValue = new CellValue(header)
});
}
sheetData.AppendChild(headerRow);
}
private void CreateRow(SheetData sheetData, ExportDataItem item, ref int rowIndex)
{
var it = item.Item;
Row row = new Row();
// 写入数据
// 1. 序号
CreateNormalCell(rowIndex, row);
// 2. 页码
CreateNormalCell(item.PageNumber, row);
// 3. 行号
CreateNormalCell(item.LineNumber, row);
// 4. 引用原文(详细信息)
CreateOriginSentenceCell(row, item);
// 5. 异常
CreateNormalCell(it.Origin, row, 3);
// 6. 建议
CreateCorrectSuggestCell(row, item);
// 7. 处理状态
CreateNormalCell(StatusText(it.IsAccept), row, 2);
sheetData.AppendChild(row);
rowIndex++;
}
private string StatusText(int status)
{
if (status == AcceptStatus.Accept) return "已采纳";
else if (status == AcceptStatus.Review) return "已复核";
else if (status == AcceptStatus.Ignore) return "已忽略";
return "未处理";
}
/// <summary>
/// 创建普通单元格
/// </summary>
/// <param name="value"></param>
/// <param name="row"></param>
/// <param name="styleIndex">样式索引id,从0开始</param>
private void CreateNormalCell(object value, Row row, uint styleIndex)
{
row.AppendChild(new Cell()
{
DataType = CellValues.String,
StyleIndex = styleIndex,
CellValue = new CellValue(value == null ? string.Empty : value.ToString()) { Space = SpaceProcessingModeValues.Preserve }
});
}
private void CreateNormalCell(object value, Row row)
{
row.AppendChild(new Cell()
{
DataType = CellValues.String,
CellValue = new CellValue(value == null ? string.Empty : value.ToString()) { Space = SpaceProcessingModeValues.Preserve }
});
}
/// <summary>
/// 创建引用原文(详细信息)单元格
/// </summary>
/// <param name="row"></param>
/// <param name="item"></param>
private void CreateOriginSentenceCell(Row row, ExportDataItem item)
{
var it = item.Item;
string originSentence = item.OriginSentence.TrimEnd();
//var startIndex = it.Tag == "i" || it.Start < originSentence.Length - 1 ? it.Start : originSentence.IndexOf(it.Origin);
var cell = new Cell()
{
DataType = CellValues.InlineString,
StyleIndex = 3
};
var beforeText = it.Start == 0 ? null : originSentence.Substring(0, it.Start);
var richTextLength = it.Origin.Length; // it.Tag == "i" ? 1 : it.Text.Length
var richText = originSentence.Substring(it.Start, richTextLength);
var afterText = it.Start >= originSentence.Length ? null : originSentence.Substring(it.Start + richTextLength);
var inlineString = new InlineString();
AppendNormalTextToCell(beforeText, inlineString);
AppendRichTextToCell(richText, inlineString, "FF0000");
AppendNormalTextToCell(afterText, inlineString);
cell.InlineString = inlineString;
row.AppendChild(cell);
}
private void CreateCorrectSuggestCell(Row row, ExportDataItem item)
{
var it = item.Item;
var cell = new Cell()
{
DataType = CellValues.InlineString,
StyleIndex = 3
};
var inlineString = new InlineString();
var suggest = it.Text;
if (it.Tag == "r")
{
string tag = "";
if (it.Type == "blacklist")
{
tag = "黑名单";
}
else
{
// 易错词 标点 不标识
if (it.Type == "confusion" || it.Type == "model" || it.Type == "other" || it.Type == "punctuation")
{
//row.CreateCell(5).SetCellValue(suggest);
}
else if (!string.IsNullOrEmpty(it.Type) && ExportConfig.ErrorTypeMap.ContainsKey(it.Type.ToLower()))
{
tag = $"【提示】{ExportConfig.ErrorTypeMap[it.Type.ToLower()]}";
}
else if (!string.IsNullOrEmpty(it.Addition) && it.Addition.Trim().Length > 0 && it.Addition != "提示")
{
tag = $"【提示】{it.Addition}";
}
}
if (!string.IsNullOrEmpty(tag))
{
AppendNormalTextToCell(suggest + " ", inlineString);
AppendRichTextToCell(tag, inlineString, "000000", "黑体");
}
else
{
AppendNormalTextToCell(suggest, inlineString);
}
}
else
{
string tag = "";
if (it.Type == "incorrect_expression")
{
tag = "表述有误";
}
else if (it.Type == "sensitive")
{
tag = "敏感词";
}
else if (it.Type == "blacklist" || it.Type == "blacklist_mask")
{
tag = "黑名单";
}
else if (it.Type == "fallen_officers")
{
tag = "疑似落马官员";
}
else if (it.Tag == "i")
{
AppendNormalTextToCell(it.Text, inlineString);
tag = " 新增";
}
else if (it.Tag == "d")
{
tag = "删除";
}
if (tag.Length > 0)
{
AppendRichTextToCell(tag, inlineString, "000000", "黑体");
}
else
{
AppendNormalTextToCell(suggest, inlineString);
}
}
cell.InlineString = inlineString;
row.AppendChild(cell);
}
private void AppendNormalTextToCell(string text, InlineString inlineString)
{
if (string.IsNullOrEmpty(text)) return;
var run = new Run(
new RunFont() { Val = "宋体" },
new FontSize() { Val = 11 },
new Text(text) { Space = SpaceProcessingModeValues.Preserve }
);
inlineString.Append(run);
}
private void AppendRichTextToCell(string text, InlineString inlineString, string color = "000000", string fontName = "宋体")
{
if (string.IsNullOrEmpty(text)) return;
var props = new RunProperties(
new FontSize() { Val = 11 }
);
if (color != "000000") props.Append(new Color() { Rgb = new HexBinaryValue(color) });
if (fontName != "宋体") props.Append(new RunFont() { Val = fontName });
var run = new Run(props, new Text(text) { Space = SpaceProcessingModeValues.Preserve });
inlineString.AppendChild(run);
}
}
}

View File

@ -13,15 +13,10 @@ using NPOI.XSSF.UserModel;
using System.Windows.Forms;
using NPOI.SS.UserModel;
using System.IO;
using SixLabors.Fonts.Tables.AdvancedTypographic;
using MathNet.Numerics.LinearAlgebra.Factorization;
using System.Linq;
using NPOI.SS.Formula.Functions;
using AIProofread.Model;
using System.Xml.Linq;
using NPOI.SS.Util;
using NPOI.HSSF.Util;
using static NPOI.HSSF.Util.HSSFColor;
using AIProofread.core;
namespace AIProofread
{
@ -442,7 +437,7 @@ namespace AIProofread
// 直接找
var range1 = document.Range(offset + item.Start, offset + item.End + 1);
// 兼容空格的全角与半角
if(item.Origin == " " && (range1.Text == " " || range1.Text == " " || range1.Text.Trim().Length == 0))
if (item.Origin == " " && (range1.Text == " " || range1.Text == " " || range1.Text.Trim().Length == 0))
{
return range1;
}
@ -477,7 +472,8 @@ namespace AIProofread
find.Wrap = WdFindWrap.wdFindContinue;
find.Execute();
if (find.Found) return range;
} catch (Exception) { }
}
catch (Exception) { }
return null;
}
@ -606,17 +602,17 @@ namespace AIProofread
// 删除文件 重新写入新数据避免出现未知不可控bug
File.Delete(sfd.FileName);
}
ProcessExport(sfd.FileName);
//ProcessExport(sfd.FileName);
CorrectResultExportor.GetInstance().ExportResult(sfd.FileName);
}
catch (Exception e)
{
Logger.Log(e);
Globals.ThisAddIn.ShowDialog("导出勘误表失败,请重试", null, null);
}
}
private static NPOI.SS.UserModel.ICell CreateCell(IRow row, int colIndex, IFont font, string text,ICellStyle style = null)
private static NPOI.SS.UserModel.ICell CreateCell(IRow row, int colIndex, IFont font, string text, ICellStyle style = null)
{
var cell = row.CreateCell(colIndex);
if (font != null)
@ -629,7 +625,7 @@ namespace AIProofread
{
cell.SetCellValue(text);
}
if(style != null)
if (style != null)
{
cell.CellStyle = style;
@ -640,6 +636,11 @@ namespace AIProofread
}
return cell;
}
private static int RGB(int red, int green, int blue)
{
return red + (green << 8) + (blue << 16);
}
private static void ProcessExport(string fileName)
{
@ -647,6 +648,7 @@ namespace AIProofread
{
var book = new XSSFWorkbook();
var sheet = book.CreateSheet("Sheet1");
#region
var simHeiFont = CreateBaseFont(book, "黑体", 11);
simHeiFont.Color = NPOI.HSSF.Util.HSSFColor.Black.Index;
// 设置表格样式
@ -674,7 +676,7 @@ namespace AIProofread
};
// 设置表头筛选及冻结 2.0.5 2024-12-30修改
sheet.CreateFreezePane(0, 1,0,1);
sheet.CreateFreezePane(0, 1, 0, 1);
sheet.SetAutoFilter(CellRangeAddress.ValueOf("A1:G1"));
// 设置表头为白色
@ -683,13 +685,13 @@ namespace AIProofread
headerFont.FontName = "黑体"; // 设置字体
headerFont.FontHeightInPoints = 11; // 字体大小
var themeColor = new XSSFColor(new byte[] { 214, 170, 105 }); // 首行背景色黑色,字体用主题金色
((XSSFFont)headerFont).SetColor(themeColor);
((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; // 水平居中
@ -718,6 +720,7 @@ namespace AIProofread
var alignCenterStyle = book.CreateCellStyle();
alignCenterStyle.VerticalAlignment = VerticalAlignment.Center;
alignCenterStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
#endregion
foreach (var item in list)
{
try
@ -738,35 +741,9 @@ namespace AIProofread
#region
string originSentence = item.OriginSentence.TrimEnd();
var startIndex = it.Tag == "i" || it.Start < originSentence.Length - 1 ? it.Start : originSentence.IndexOf(it.Origin);
//var endIndex = startIndex + (it.Tag == "i" ? it.Text.Length : it.Origin.Length);
//if (it.Tag == "i")
//{
// // ˽
// // 对查找内容引用红色
// try
// {
// originSentence = originSentence.Substring(0, startIndex) + GetInsertContentByLength(it.Text.Length) + originSentence.Substring(startIndex);
// }
// catch (Exception e)
// {
// Logger.Log(e);
// }
//}
//// 执行查找
//if (it.Tag == "i")
//{
// var blankText = ToolUtil.GetBlankText(it.Text.Length);
// startIndex = originSentence.IndexOf(blankText);
//}
XSSFRichTextString originText = new XSSFRichTextString(originSentence);
originText.ApplyFont(blackFont);
//// 不要越界鸟(不一定采用后端返回数据)
//if (startIndex < endIndex && startIndex < originSentence.Length - 1 && endIndex < originSentence.Length - 1)
//{
// // 对查找内容引用红色
// originText.ApplyFont(startIndex, endIndex, redFont);
//}
try
{
originText.ApplyFont(it.Start, it.Start + (it.Tag == "i" ? it.Text.Length : it.Origin.Length), redFont);
@ -848,7 +825,7 @@ namespace AIProofread
{
tag = "黑名单";
}
else if(it.Type == "fallen_officers")
else if (it.Type == "fallen_officers")
{
tag = "落马官员";
}

View File

@ -1,23 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="BouncyCastle.Cryptography" version="2.3.1" targetFramework="net462" />
<package id="DocumentFormat.OpenXml" version="3.3.0" targetFramework="net462" />
<package id="DocumentFormat.OpenXml.Framework" version="3.3.0" targetFramework="net462" />
<package id="Enums.NET" version="4.0.1" targetFramework="net462" />
<package id="ExtendedNumerics.BigDecimal" version="2025.1001.2.129" targetFramework="net462" />
<package id="MathNet.Numerics.Signed" version="5.0.0" targetFramework="net462" />
<package id="Microsoft.IO.RecyclableMemoryStream" version="3.0.0" targetFramework="net462" />
<package id="Microsoft.IO.RecyclableMemoryStream" version="3.0.1" targetFramework="net462" />
<package id="Microsoft.Web.WebView2" version="1.0.2210.55" targetFramework="net462" />
<package id="NPOI" version="2.7.1" targetFramework="net462" />
<package id="SharpZipLib" version="1.4.2" targetFramework="net462" />
<package id="SixLabors.Fonts" version="1.0.1" targetFramework="net462" />
<package id="SixLabors.ImageSharp" version="2.1.8" targetFramework="net462" />
<package id="System.Buffers" version="4.5.1" targetFramework="net462" />
<package id="System.ComponentModel.Annotations" version="5.0.0" targetFramework="net462" />
<package id="System.Configuration.ConfigurationManager" version="6.0.0" targetFramework="net462" />
<package id="System.Memory" version="4.5.5" targetFramework="net462" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net462" />
<package id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" targetFramework="net462" />
<package id="System.Security.AccessControl" version="6.0.0" targetFramework="net462" />
<package id="System.Security.Cryptography.Pkcs" version="6.0.3" targetFramework="net462" />
<package id="System.Security.Cryptography.Xml" version="6.0.1" targetFramework="net462" />
<package id="System.Security.Cryptography.Xml" version="8.0.2" targetFramework="net462" />
<package id="System.Security.Permissions" version="6.0.0" targetFramework="net462" />
<package id="System.Security.Principal.Windows" version="5.0.0" targetFramework="net462" />
<package id="System.Text.Encoding.CodePages" version="5.0.0" targetFramework="net462" />

View File

@ -36,7 +36,6 @@
this.IconClose = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label();
this.panelLog = new System.Windows.Forms.Panel();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.IconClose)).BeginInit();
this.panelLog.SuspendLayout();
@ -44,12 +43,13 @@
//
// LabelLog
//
this.LabelLog.AutoEllipsis = true;
this.LabelLog.Font = new System.Drawing.Font("微软雅黑", 10F);
this.LabelLog.Location = new System.Drawing.Point(2, 2);
this.LabelLog.MaximumSize = new System.Drawing.Size(296, 0);
this.LabelLog.MinimumSize = new System.Drawing.Size(296, 0);
this.LabelLog.MaximumSize = new System.Drawing.Size(296, 114);
this.LabelLog.MinimumSize = new System.Drawing.Size(296, 114);
this.LabelLog.Name = "LabelLog";
this.LabelLog.Size = new System.Drawing.Size(296, 21);
this.LabelLog.Size = new System.Drawing.Size(296, 114);
this.LabelLog.TabIndex = 0;
this.LabelLog.Text = "版本检测中 ...";
this.LabelLog.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
@ -114,31 +114,18 @@
//
// panelLog
//
this.panelLog.AutoScroll = true;
this.panelLog.Controls.Add(this.LabelLog);
this.panelLog.Location = new System.Drawing.Point(40, 58);
this.panelLog.Name = "panelLog";
this.panelLog.Size = new System.Drawing.Size(300, 114);
this.panelLog.TabIndex = 8;
//
// richTextBox1
//
this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.richTextBox1.Location = new System.Drawing.Point(237, 149);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.ReadOnly = true;
this.richTextBox1.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
this.richTextBox1.Size = new System.Drawing.Size(100, 96);
this.richTextBox1.TabIndex = 9;
this.richTextBox1.Text = "";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(380, 260);
this.Controls.Add(this.richTextBox1);
this.Controls.Add(this.panelLog);
this.Controls.Add(this.panel1);
this.Controls.Add(this.ButtonProcess);
@ -169,7 +156,6 @@
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Panel panelLog;
private System.Windows.Forms.RichTextBox richTextBox1;
}
}

View File

@ -187,15 +187,8 @@ namespace updater
private void ProcessUpdate(UpgradeModel update)
{
this.upgradeInfo = update.Info;
//richTextBox1.Text
richTextBox1.Text = update.Info.Message
+ @"Com加载项勾选
office或wps的版本
Com加载项勾选
windowS10或11wps在安装插件";
LabelLog.Text = update.Info.Message;
if (localVersion == null || update.Info.NeedUpgrade(localVersion.Version))
{

View File

@ -5,11 +5,15 @@ namespace UtilLib
public class ToolUtil
{
public static string GetBlankText(int len)
{
return GetBlankText(len, " ");
}
public static string GetBlankText(int len,string blankText)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < len; i++)
{
sb.Append(" ");
sb.Append(blankText);
}
return sb.ToString();
}