fixed: 勘误表内容居中及定位错误;全角与半角空格导致定位不正确
This commit is contained in:
parent
b8f7341b9d
commit
94e7327dce
@ -622,7 +622,10 @@ namespace AIProofread.Model
|
||||
List<InsertMarkData> insertMarks = new List<InsertMarkData>();
|
||||
foreach (var correct in list)
|
||||
{
|
||||
Logger.Log(string.Format("correct content:{0}", correct.Insert));
|
||||
if(Logger.LoggerForm != null)
|
||||
{
|
||||
Logger.Log(string.Format("correct content:{0}", correct.Insert));
|
||||
}
|
||||
int currentOffset = correct.SentenceOffset;
|
||||
if (correct.CorrectItems != null && correct.CorrectItems.Count > 0)
|
||||
{
|
||||
|
@ -12,7 +12,7 @@ namespace AIProofread.Model
|
||||
public string OriginSentence { get; set; }
|
||||
public CorrectItem Item { get; set; }
|
||||
|
||||
private static readonly int MAX_WORD_LENGTH = 5;
|
||||
private static readonly int MAX_WORD_LENGTH = 128;
|
||||
|
||||
public ExportDataItem(CorrectItem item, int pageNumber, int lineNumber,string originSentence = "")
|
||||
{
|
||||
@ -25,7 +25,8 @@ namespace AIProofread.Model
|
||||
public static string GetSentence(ProofreadItem item)
|
||||
{
|
||||
var sentence = item.OriginSentence;
|
||||
if (sentence.Length <= MAX_WORD_LENGTH)
|
||||
var isInsert = item.content.Tag == "i";
|
||||
if (sentence.Length <= MAX_WORD_LENGTH && !isInsert)
|
||||
{
|
||||
return sentence;
|
||||
}
|
||||
@ -38,8 +39,19 @@ namespace AIProofread.Model
|
||||
var sb = new StringBuilder();
|
||||
foreach (Microsoft.Office.Interop.Word.Range s in sentences)
|
||||
{
|
||||
sb.Append(s.Text);
|
||||
var str = s.Text;
|
||||
if (isInsert && range.Start >= s.Start && range.End <= s.End)
|
||||
{
|
||||
sb.Append(str.Replace(" ", "˽"));
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(str);
|
||||
}
|
||||
}
|
||||
var first = sentences.First;
|
||||
item.content.Start = range.Start - first.Start;
|
||||
item.content.End = range.End - first.Start;
|
||||
return sb.ToString().Trim();
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ namespace AIProofread
|
||||
public void CheckDocumentClosed(object sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
var existsList = new List<string>();
|
||||
Logger.Log("检测文档是否关闭 ...");
|
||||
//Logger.Log("检测文档是否关闭 ...");
|
||||
try
|
||||
{
|
||||
if (documentList.Count == 0 || CurrentWordApplication.Documents.Count == documentList.Count) return;
|
||||
|
@ -43,6 +43,7 @@ namespace AIProofread.core
|
||||
// 检测状态
|
||||
public bool isChecking = false;
|
||||
public string checkingSummary;
|
||||
public string checkingLocation;
|
||||
public string checkingKey;
|
||||
|
||||
public string GetCheckStatus()
|
||||
@ -50,17 +51,19 @@ namespace AIProofread.core
|
||||
return JSONObject.Create()
|
||||
.Put("isChecking", isChecking)
|
||||
.Put("checkingKey", checkingKey)
|
||||
.Put("checkingLocation", checkingLocation)
|
||||
.Put("checkingSummary", checkingSummary)
|
||||
.ToString();
|
||||
}
|
||||
|
||||
public void SetCheckingData(bool isChecking, string checkingKey, string checkingSummary)
|
||||
public void SetCheckingData(bool isChecking, string checkingKey, string checkingSummary,string checkingLocation)
|
||||
{
|
||||
if (isChecking)
|
||||
{
|
||||
this.isChecking = isChecking;
|
||||
this.checkingKey = checkingKey;
|
||||
this.checkingSummary = checkingSummary;
|
||||
this.checkingLocation = checkingLocation;
|
||||
Globals.ThisAddIn.ribbon.SetDetectionBtnStatus(false);
|
||||
}
|
||||
else
|
||||
@ -68,6 +71,7 @@ namespace AIProofread.core
|
||||
this.isChecking = false;
|
||||
this.checkingKey = null;
|
||||
this.checkingSummary = null;
|
||||
this.checkingLocation = null;
|
||||
Globals.ThisAddIn.ribbon.SetDetectionBtnStatus(true);
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ using AIProofread.Model;
|
||||
using System.Xml.Linq;
|
||||
using NPOI.SS.Util;
|
||||
using NPOI.HSSF.Util;
|
||||
using static NPOI.HSSF.Util.HSSFColor;
|
||||
|
||||
namespace AIProofread
|
||||
{
|
||||
@ -434,6 +435,10 @@ namespace AIProofread
|
||||
}
|
||||
// 直接找
|
||||
var range1 = document.Range(offset + item.Start, offset + item.End + 1);
|
||||
if(item.Origin == " " && range1.Text == " " || range1.Text == " ")
|
||||
{
|
||||
return range1;
|
||||
}
|
||||
//
|
||||
if (range1.Text == item.Origin)
|
||||
{
|
||||
@ -520,6 +525,11 @@ namespace AIProofread
|
||||
var findOffset = paraRange.Start + start + (prefix != null ? prefix.Length : 0);
|
||||
prevOffset = start;
|
||||
var range = document.Range(findOffset, findOffset + wordEnd - wordStart + 1);
|
||||
|
||||
if (item.Origin == " " && range.Text == " " || range.Text == " ")
|
||||
{
|
||||
return range;
|
||||
}
|
||||
if (range.Text == item.Origin) { return range; }
|
||||
}
|
||||
// 直接定位查找
|
||||
@ -667,6 +677,10 @@ namespace AIProofread
|
||||
var wrapTextStyle = book.CreateCellStyle();
|
||||
wrapTextStyle.WrapText = true;
|
||||
wrapTextStyle.VerticalAlignment = VerticalAlignment.Center;
|
||||
|
||||
var alignCenterStyle = book.CreateCellStyle();
|
||||
alignCenterStyle.VerticalAlignment = VerticalAlignment.Center;
|
||||
alignCenterStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
|
||||
foreach (var item in list)
|
||||
{
|
||||
try
|
||||
@ -675,30 +689,56 @@ namespace AIProofread
|
||||
row = sheet.CreateRow(id);
|
||||
row.Height = -1;
|
||||
row.CreateCell(0).SetCellValue(id);
|
||||
row.CreateCell(1).SetCellValue(item.PageNumber);
|
||||
row.CreateCell(2).SetCellValue(item.LineNumber);
|
||||
// 页码
|
||||
var pageCell = row.CreateCell(1);
|
||||
pageCell.CellStyle = alignCenterStyle;
|
||||
pageCell.SetCellValue(item.PageNumber);
|
||||
// 行号
|
||||
var lineCell = row.CreateCell(2);
|
||||
lineCell.CellStyle = alignCenterStyle;
|
||||
lineCell.SetCellValue(item.LineNumber);
|
||||
|
||||
#region 引用原文内容
|
||||
string originSentence = item.OriginSentence;
|
||||
if (it.Tag == "i")
|
||||
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
|
||||
{
|
||||
// ˽
|
||||
// 对查找内容引用红色
|
||||
try
|
||||
{
|
||||
originSentence = originSentence.Substring(0, it.Start) + GetInsertContentByLength(it.Text.Length) + originSentence.Substring(it.Start);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Log(e);
|
||||
}
|
||||
originText.ApplyFont(it.Start, it.Start + (it.Tag == "i" ? it.Text.Length : it.Origin.Length), redFont);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Log(e);
|
||||
}
|
||||
|
||||
XSSFRichTextString originText = new XSSFRichTextString(originSentence.TrimEnd());
|
||||
originText.ApplyFont(blackFont);
|
||||
var startIndex = it.Tag == "i" ? it.Start : originSentence.IndexOf(it.Origin);
|
||||
// 对查找内容引用红色
|
||||
originText.ApplyFont(it.Start, it.Start + (it.Tag == "i" ? it.Text.Length : it.Origin.Length), redFont);
|
||||
var oriCell = row.CreateCell(3);
|
||||
// 设置单元格内容自动换行
|
||||
oriCell.CellStyle = wrapTextStyle;
|
||||
@ -797,7 +837,9 @@ namespace AIProofread
|
||||
// 处理状态
|
||||
var statusValue = new XSSFRichTextString(StatusText(it.IsAccept));
|
||||
statusValue.ApplyFont(simHeiFont);
|
||||
row.CreateCell(6).SetCellValue(statusValue);
|
||||
var cellStatus = row.CreateCell(6);
|
||||
cellStatus.CellStyle = alignCenterStyle;
|
||||
cellStatus.SetCellValue(statusValue);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user