diff --git a/.vs/AIProofread/v17/.suo b/.vs/AIProofread/v17/.suo index 8e4fc1a..0a8a246 100644 Binary files a/.vs/AIProofread/v17/.suo and b/.vs/AIProofread/v17/.suo differ diff --git a/AIProofread/AIProofread.csproj b/AIProofread/AIProofread.csproj index ae7b7c0..d844da6 100644 --- a/AIProofread/AIProofread.csproj +++ b/AIProofread/AIProofread.csproj @@ -128,6 +128,12 @@ ..\packages\BouncyCastle.Cryptography.2.3.1\lib\net461\BouncyCastle.Cryptography.dll + + ..\packages\DocumentFormat.OpenXml.3.3.0\lib\net46\DocumentFormat.OpenXml.dll + + + ..\packages\DocumentFormat.OpenXml.Framework.3.3.0\lib\net46\DocumentFormat.OpenXml.Framework.dll + ..\packages\Enums.NET.4.0.1\lib\net45\Enums.NET.dll @@ -140,8 +146,11 @@ ..\packages\MathNet.Numerics.Signed.5.0.0\lib\net461\MathNet.Numerics.dll - - ..\packages\Microsoft.IO.RecyclableMemoryStream.3.0.0\lib\netstandard2.0\Microsoft.IO.RecyclableMemoryStream.dll + + ..\packages\Microsoft.IO.RecyclableMemoryStream.3.0.1\lib\netstandard2.0\Microsoft.IO.RecyclableMemoryStream.dll + + + True ..\packages\Microsoft.Web.WebView2.1.0.2210.55\lib\net45\Microsoft.Web.WebView2.Core.dll @@ -167,6 +176,7 @@ ..\packages\NPOI.2.7.1\lib\netstandard2.0\NPOI.OpenXmlFormats.dll + ..\packages\SixLabors.Fonts.1.0.1\lib\netstandard2.0\SixLabors.Fonts.dll @@ -177,6 +187,9 @@ ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + ..\packages\System.ComponentModel.Annotations.5.0.0\lib\net461\System.ComponentModel.Annotations.dll + @@ -203,8 +216,8 @@ ..\packages\System.Security.Cryptography.Pkcs.6.0.3\lib\net461\System.Security.Cryptography.Pkcs.dll - - ..\packages\System.Security.Cryptography.Xml.6.0.1\lib\net461\System.Security.Cryptography.Xml.dll + + ..\packages\System.Security.Cryptography.Xml.8.0.2\lib\net462\System.Security.Cryptography.Xml.dll ..\packages\System.Security.Permissions.6.0.0\lib\net461\System.Security.Permissions.dll @@ -373,6 +386,7 @@ + diff --git a/AIProofread/Config.cs b/AIProofread/Config.cs index 34fa015..54a59b2 100644 --- a/AIProofread/Config.cs +++ b/AIProofread/Config.cs @@ -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; diff --git a/AIProofread/Controls/BaseWinForm.cs b/AIProofread/Controls/BaseWinForm.cs index c2da513..b85f357 100644 --- a/AIProofread/Controls/BaseWinForm.cs +++ b/AIProofread/Controls/BaseWinForm.cs @@ -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); diff --git a/AIProofread/Controls/FormLogin.Designer.cs b/AIProofread/Controls/FormLogin.Designer.cs index 11f178d..06f9273 100644 --- a/AIProofread/Controls/FormLogin.Designer.cs +++ b/AIProofread/Controls/FormLogin.Designer.cs @@ -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"; diff --git a/AIProofread/Controls/FormLogin.cs b/AIProofread/Controls/FormLogin.cs index 9f8efc0..997f34c 100644 --- a/AIProofread/Controls/FormLogin.cs +++ b/AIProofread/Controls/FormLogin.cs @@ -61,6 +61,5 @@ namespace AIProofread.Controls InitWebView(web, Config.WebPath("login?action=" + this.action + "&version=" + Config.APP_VERSION + "&t=" + DateTime.Now.Ticks), "login"); } - } } diff --git a/AIProofread/Model/ExportDataItem.cs b/AIProofread/Model/ExportDataItem.cs index d28a47b..3ebbcac 100644 --- a/AIProofread/Model/ExportDataItem.cs +++ b/AIProofread/Model/ExportDataItem.cs @@ -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 { diff --git a/AIProofread/Ribbon1.Designer.cs b/AIProofread/Ribbon1.Designer.cs index 9e8b2a8..1325472 100644 --- a/AIProofread/Ribbon1.Designer.cs +++ b/AIProofread/Ribbon1.Designer.cs @@ -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 diff --git a/AIProofread/Ribbon1.cs b/AIProofread/Ribbon1.cs index 85174ef..e27ed56 100644 --- a/AIProofread/Ribbon1.cs +++ b/AIProofread/Ribbon1.cs @@ -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); + } } } diff --git a/AIProofread/Ribbon1.resx b/AIProofread/Ribbon1.resx index 3df9d74..368446c 100644 --- a/AIProofread/Ribbon1.resx +++ b/AIProofread/Ribbon1.resx @@ -225,6 +225,9 @@ True + + True + True diff --git a/AIProofread/ThisAddIn.cs b/AIProofread/ThisAddIn.cs index 1356cfe..f5ba264 100644 --- a/AIProofread/ThisAddIn.cs +++ b/AIProofread/ThisAddIn.cs @@ -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; diff --git a/AIProofread/app.config b/AIProofread/app.config index 08b3fbf..ef33675 100644 --- a/AIProofread/app.config +++ b/AIProofread/app.config @@ -12,7 +12,7 @@ - + @@ -22,6 +22,10 @@ + + + + \ No newline at end of file diff --git a/AIProofread/core/CorrectResultExportor.cs b/AIProofread/core/CorrectResultExportor.cs new file mode 100644 index 0000000..831b568 --- /dev/null +++ b/AIProofread/core/CorrectResultExportor.cs @@ -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); + } + /// + /// 使用Excel COM导出 + /// + /// + 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(); + stylesPart.Stylesheet = CreateStyleSheet(); + stylesPart.Stylesheet.Save(); + + // 创建工作簿 + workbookPart.Workbook = new Workbook(); + + WorksheetPart worksheetPart = workbookPart.AddNewPart(); + 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(); + // 创建表头 + 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 "未处理"; + } + + /// + /// 创建普通单元格 + /// + /// + /// + /// 样式索引id,从0开始 + 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 } + }); + } + + /// + /// 创建引用原文(详细信息)单元格 + /// + /// + /// + 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); + } + } +} diff --git a/AIProofread/core/DocumentUtil.cs b/AIProofread/core/DocumentUtil.cs index e418f2d..8035e5b 100644 --- a/AIProofread/core/DocumentUtil.cs +++ b/AIProofread/core/DocumentUtil.cs @@ -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 = "落马官员"; } diff --git a/AIProofread/packages.config b/AIProofread/packages.config index dfc8c51..db72e38 100644 --- a/AIProofread/packages.config +++ b/AIProofread/packages.config @@ -1,23 +1,26 @@  + + - + + - + diff --git a/updater/Form1.Designer.cs b/updater/Form1.Designer.cs index 64c771f..80a9a76 100644 --- a/updater/Form1.Designer.cs +++ b/updater/Form1.Designer.cs @@ -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; } } diff --git a/updater/Form1.cs b/updater/Form1.cs index ab9bf1c..168a44d 100644 --- a/updater/Form1.cs +++ b/updater/Form1.cs @@ -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或11。在安装插件时,需要先装wps在安装插件,在安装插件。否则菜单中不会显示校对王插件入口"; + + LabelLog.Text = update.Info.Message; if (localVersion == null || update.Info.NeedUpgrade(localVersion.Version)) { diff --git a/util-lib/ToolUtil.cs b/util-lib/ToolUtil.cs index f08b946..76ff48d 100644 --- a/util-lib/ToolUtil.cs +++ b/util-lib/ToolUtil.cs @@ -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(); }