更新导出样式
This commit is contained in:
parent
3a3d128ab0
commit
7426273320
@ -314,7 +314,7 @@ namespace AIProofread
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread.Sleep(3000);
|
||||
Thread.Sleep(500);
|
||||
//FormMessage loadingDialog = null;
|
||||
//// 大于15W字符无法校对
|
||||
//Task.Run(() =>
|
||||
|
@ -613,8 +613,14 @@ namespace AIProofread.Model
|
||||
if (marks.ContainsKey(item.Id)) continue;
|
||||
Logger.Log(string.Format("mark type {0} data {1}->{2}", item.Tag, item.Origin, item.Text));
|
||||
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)
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Microsoft.Office.Interop.Word;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UtilLib;
|
||||
|
||||
namespace AIProofread.Model
|
||||
@ -11,6 +12,8 @@ namespace AIProofread.Model
|
||||
public string OriginSentence { 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 = "")
|
||||
{
|
||||
Item = item;
|
||||
@ -19,6 +22,27 @@ namespace AIProofread.Model
|
||||
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)
|
||||
{
|
||||
List<ExportDataItem> list = new List<ExportDataItem>();
|
||||
@ -37,7 +61,7 @@ namespace AIProofread.Model
|
||||
var pageNumber = range.get_Information(WdInformation.wdActiveEndPageNumber);
|
||||
// 获取书签在当前页面的行数
|
||||
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) =>
|
||||
|
@ -20,6 +20,7 @@ using NPOI.SS.Formula.Functions;
|
||||
using AIProofread.Model;
|
||||
using System.Xml.Linq;
|
||||
using NPOI.SS.Util;
|
||||
using NPOI.HSSF.Util;
|
||||
|
||||
namespace AIProofread
|
||||
{
|
||||
@ -560,14 +561,15 @@ namespace AIProofread
|
||||
}
|
||||
ProcessExport(sfd.FileName);
|
||||
}
|
||||
catch (Exception)
|
||||
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)
|
||||
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)
|
||||
@ -580,7 +582,15 @@ namespace AIProofread
|
||||
{
|
||||
cell.SetCellValue(text);
|
||||
}
|
||||
if(style != null)
|
||||
{
|
||||
cell.CellStyle = style;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
cell.CellStyle.WrapText = true;
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
|
||||
@ -603,61 +613,49 @@ namespace AIProofread
|
||||
style.BorderRight = NPOI.SS.UserModel.BorderStyle.None;
|
||||
style.WrapText = true;
|
||||
|
||||
sheet.SetDefaultColumnStyle(0, style);
|
||||
sheet.SetDefaultColumnStyle(1, style);
|
||||
sheet.SetDefaultColumnStyle(2, style);
|
||||
sheet.SetDefaultColumnStyle(3, style);
|
||||
sheet.SetDefaultColumnStyle(4, style);
|
||||
sheet.SetDefaultColumnStyle(5, style);
|
||||
sheet.SetDefaultColumnStyle(6, style);
|
||||
|
||||
|
||||
// 表头设置
|
||||
var row = sheet.CreateRow(0);
|
||||
CreateCell(row, 0, simHeiFont, "序号");
|
||||
CreateCell(row, 1, simHeiFont, "页");
|
||||
CreateCell(row, 2, simHeiFont, "行");
|
||||
CreateCell(row, 3, simHeiFont, "详细信息");
|
||||
CreateCell(row, 4, simHeiFont, "异常");
|
||||
CreateCell(row, 5, simHeiFont, "建议");
|
||||
CreateCell(row, 6, simHeiFont, "处理状态");
|
||||
|
||||
|
||||
// 设置表头筛选及冻结
|
||||
sheet.CreateFreezePane(0, 1,0,1);
|
||||
sheet.SetAutoFilter(CellRangeAddress.ValueOf("A1:G1"));
|
||||
|
||||
// 设置表头背景颜色为黑色
|
||||
var headerStyle = CreateBaseCellStyle(book);
|
||||
var headerFont = CreateBaseFont(book, "黑体", 11);
|
||||
|
||||
headerFont.Color = NPOI.HSSF.Util.HSSFColor.White.Index;
|
||||
headerStyle.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
|
||||
headerStyle.FillPattern = FillPattern.SolidForeground;
|
||||
headerStyle.SetFont(headerFont);
|
||||
|
||||
for (int i = 0; i < 7; i++)
|
||||
{
|
||||
var cell = row.Cells[i];
|
||||
cell.CellStyle = headerStyle;
|
||||
//cell.CellStyle.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground;
|
||||
//// 设置背景
|
||||
//cell.CellStyle.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground;
|
||||
//cell.CellStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Red.Index;
|
||||
//cell.CellStyle.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
|
||||
}
|
||||
|
||||
|
||||
//sheet.AutoFilter = new NPOI.SS.Util.AutoFilter(0, 0, new NPOI.SS.Util.AreaReference("A1:G1"));
|
||||
|
||||
|
||||
// 设置宽度
|
||||
sheet.SetColumnWidth(0, 0); // 详细信息
|
||||
sheet.SetColumnWidth(0, 1); // 序号
|
||||
sheet.SetColumnHidden(0, true); // 隐藏序号
|
||||
sheet.SetColumnWidth(3, 80 * 256); // 详细信息
|
||||
sheet.SetColumnWidth(4, 20 * 256); // 异常
|
||||
sheet.SetColumnWidth(5, 20 * 256); // 建议
|
||||
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);
|
||||
row.Height = 40 * 20; // 首行加高
|
||||
for (int i = 0; i < 7; i++)
|
||||
{
|
||||
sheet.SetDefaultColumnStyle(i, style);
|
||||
var cell = CreateCell(row, i, headerFont, headerTitles[i], headerStyle);
|
||||
}
|
||||
|
||||
var blackFont = CreateBaseFont(book, NPOI.HSSF.Util.HSSFColor.Black.Index);
|
||||
var redFont = CreateBaseFont(book, NPOI.HSSF.Util.HSSFColor.Red.Index);
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Microsoft.Office.Interop.Word;
|
||||
using Newtonsoft.Json;
|
||||
using NPOI.POIFS.FileSystem;
|
||||
using NPOI.XWPF.UserModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -23,11 +24,11 @@ namespace AIProofread
|
||||
{
|
||||
string ext = doc.FullName.ToLower();
|
||||
// 如果是
|
||||
if (ext.EndsWith(".wps") || doc.Paragraphs.Count < 200 || doc.Tables.Count < 20)
|
||||
{
|
||||
// 如果段落数小于200或表格小于20 则直接使用vsto 获取数据
|
||||
return GetAllTextByVSTO(doc);
|
||||
}
|
||||
//if (ext.EndsWith(".wps") || doc.Paragraphs.Count < 200 || doc.Tables.Count < 20)
|
||||
//{
|
||||
// // 如果段落数小于200或表格小于20 则直接使用vsto 获取数据
|
||||
// return GetAllTextByVSTO(doc);
|
||||
//}
|
||||
// 创建临时文件 方便数据读取
|
||||
string docPath = Tools.GetReadDocumentFilePath(doc);
|
||||
|
||||
@ -58,7 +59,7 @@ namespace AIProofread
|
||||
{
|
||||
foreach (var pc in cell.Paragraphs)
|
||||
{
|
||||
//list.Add(pc.ParagraphText);
|
||||
list.Add(new DocumentText(pc.ParagraphText.Replace("\u0002", ""), paragraphNumber));
|
||||
paragraphNumber++;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user