术语替换-先完整准确匹配,匹配了就跳过,否则就关键字匹配替换
continuous-integration/drone/push Build is running Details

Test_IRC_Net10
hang 2026-06-04 16:28:17 +08:00
parent 152a142d82
commit 2b03f382bd
3 changed files with 125 additions and 30 deletions

View File

@ -166,6 +166,31 @@ public static class ExcelExportHelper
// ClosedXML 获取第一个工作表
var worksheet = workbook.Worksheet(1); // 索引从1开始
#region sheet 名字修改 以及导表文件名字修改
var currentSheetName = worksheet.Name;
// 查找匹配的工作表名(支持部分匹配)
var findObj = replaceObjectList.FirstOrDefault(t => currentSheetName.Contains(t.Name));
if (findObj != null)
{
// 直接匹配或替换包含关键字的工作表名
var newSheetName = currentSheetName.Replace(findObj.Name, findObj.TrialName);
worksheet.Name = newSheetName;
}
var findFileName = replaceObjectList.FirstOrDefault(t => fileName.Contains(t.Name));
if (findFileName != null)
{
// 直接匹配或替换包含关键字的工作表名
var newFileName = currentSheetName.Replace(findFileName.Name, findFileName.TrialName);
fileName = newFileName;
}
#endregion
// 获取使用的行范围(不包括空行)
var rowsUsed = worksheet.RowsUsed();
@ -178,11 +203,35 @@ public static class ExcelExportHelper
{
var cellValue = cell.GetString();
var find = replaceObjectList.FirstOrDefault(t => t.Name == cellValue);
var newValue = cellValue;
var isChanged = false;
var find = replaceObjectList.FirstOrDefault(t => cellValue.Trim() == t.Name.Trim());
if (find != null)
{
cell.SetValue(find.TrialName);
newValue = newValue.Replace(find.Name, find.TrialName);
isChanged = true;
}
else
{
// 遍历所有替换规则,进行关键字匹配替换
foreach (var replaceItem in replaceObjectList.Where(t => cellValue.Contains(t.Name)))
{
newValue = newValue.Replace(replaceItem.Name, replaceItem.TrialName);
isChanged = true;
}
}
if (isChanged)
{
cell.SetValue(newValue);
}
}
}
}
@ -192,7 +241,7 @@ public static class ExcelExportHelper
workbook.SaveAs(memoryStream2);
memoryStream2.Seek(0, SeekOrigin.Begin);
templateStream = memoryStream2;
}
@ -305,7 +354,7 @@ public static class ExcelExportHelper
}
public static async Task<(MemoryStream, string)> DataExport_NpoiTestAsync(string code, ExcelExportInfo data, IRepository<CommonDocument> _commonDocumentRepository, IWebHostEnvironment _hostEnvironment, IDictionaryService? _dictionaryService = null, Type? translateType = null, CriterionType? criterionType = null, DynamicColumnConfig? dynamicColumnConfig = null)
public static async Task<(MemoryStream, string)> DataExport_ClosedXMLAsync(string code, ExcelExportInfo data, IRepository<CommonDocument> _commonDocumentRepository, IWebHostEnvironment _hostEnvironment, IDictionaryService? _dictionaryService = null, Type? translateType = null, CriterionType? criterionType = null, DynamicColumnConfig? dynamicColumnConfig = null)
{
var isEn_US = CultureInfo.CurrentCulture.Name == StaticData.CultureInfo.en_US;
//判断是否有字典翻译
@ -444,30 +493,76 @@ public static class ExcelExportHelper
// ClosedXML 获取第一个工作表
var worksheet = workbook.Worksheet(1); // 索引从1开始
#region sheet 名字修改 以及导表文件名字修改
var currentSheetName = worksheet.Name;
// 查找匹配的工作表名(支持部分匹配)
var findObj = replaceObjectList.FirstOrDefault(t => currentSheetName.Contains(t.Name));
if (findObj != null)
{
// 直接匹配或替换包含关键字的工作表名
var newSheetName = currentSheetName.Replace(findObj.Name, findObj.TrialName);
worksheet.Name = newSheetName;
}
var findFileName = replaceObjectList.FirstOrDefault(t => fileName.Contains(t.Name));
if (findFileName != null)
{
// 直接匹配或替换包含关键字的工作表名
var newFileName = currentSheetName.Replace(findFileName.Name, findFileName.TrialName);
fileName = newFileName;
}
#endregion
// 获取使用的行范围(不包括空行)
var rowsUsed = worksheet.RowsUsed();
foreach (var row in rowsUsed)
{
// 获取该行使用的列范围
var cellsUsed = row.CellsUsed();
// 获取该行有数据的单元格
var cellsUsed = row.CellsUsed(c => c.DataType == XLDataType.Text);
foreach (var cell in cellsUsed)
{
var cellValue = cell.GetString();
var cellValue = cell.GetString();
var newValue = cellValue;
var isChanged = false;
var find = replaceObjectList.FirstOrDefault(t => t.Name == cellValue);
if (find != null)
var find = replaceObjectList.FirstOrDefault(t => cellValue.Trim() == t.Name.Trim());
if (find != null)
{
newValue = newValue.Replace(find.Name, find.TrialName);
isChanged = true;
}
else
{
// 遍历所有替换规则,进行关键字匹配替换
foreach (var replaceItem in replaceObjectList.Where(t => cellValue.Contains(t.Name)))
{
cell.SetValue(find.TrialName);
newValue = newValue.Replace(replaceItem.Name, replaceItem.TrialName);
isChanged = true;
}
}
if (isChanged)
{
cell.SetValue(newValue);
}
}
}
}
#endregion
@ -479,7 +574,7 @@ public static class ExcelExportHelper
var worksheet = workbook.Worksheet(1);
// 获取行ClosedXML 行索引从1开始AutoColumnTitleRowIndex 已经改了保持不变)
var cdicsRow = worksheet.Row(dynamicColumnConfig.AutoColumnTitleRowIndex-1); // 原 NPOI: -1
var cdicsRow = worksheet.Row(dynamicColumnConfig.AutoColumnTitleRowIndex - 1); // 原 NPOI: -1
var titelRow = worksheet.Row(dynamicColumnConfig.AutoColumnTitleRowIndex); // 原 NPOI: 不变
var templateRow = worksheet.Row(dynamicColumnConfig.AutoColumnTitleRowIndex + 1); // 原 NPOI: +1
@ -518,9 +613,9 @@ public static class ExcelExportHelper
// 将后面的列向前移动
for (var i = 0; i < originTotalEndIndex - removeIndex; i++)
{
int currentCol = removeIndex + i ;
int nextCol = removeIndex + i + 1;
int currentCol = removeIndex + i;
int nextCol = removeIndex + i + 1;
Console.WriteLine(titelRow.Cell(nextCol).GetString());
@ -537,7 +632,7 @@ public static class ExcelExportHelper
// 创建新的列ClosedXML 不需要显式创建,直接设置值即可)
for (int i = originRemoveEndIndex; i < originRemoveEndIndex + needAddCount; i++)
{
int colIndex = i + 1;
int colIndex = i + 1;
// 不需要 CreateCell直接设置值即可
if (isCdics)
@ -553,8 +648,8 @@ public static class ExcelExportHelper
for (int i = totalColunmEndIndex; i > dynamicColunmEndIndex; i--)
{
int currentCol = i ;
int sourceCol = i - gap ;
int currentCol = i;
int sourceCol = i - gap;
titelRow.Cell(currentCol).SetValue(titelRow.Cell(sourceCol).GetString());
templateRow.Cell(currentCol).SetValue(templateRow.Cell(sourceCol).GetString());
@ -568,7 +663,7 @@ public static class ExcelExportHelper
// 设置动态 Title
for (int i = dynamicColunmStartIndex; i < dynamicColunmStartIndex + needAddCount; i++)
{
int colIndex = i ;
int colIndex = i;
var index = i - dynamicColunmStartIndex;
var name = dynamicColumnConfig.ColumnIdNameList[index].Name;
@ -649,11 +744,11 @@ public static class ExcelExportHelper
if (isExcelAddDataWithName)
{
writeIndex = dynamicColumnConfig.ColumnNameList.IndexOf(iteObjDic[dynamicColumnConfig.DynamicItemTitleName].ToString()) + dynamicColumnConfig.AutoColumnStartIndex ; // +1 因为 ClosedXML 列从1开始
writeIndex = dynamicColumnConfig.ColumnNameList.IndexOf(iteObjDic[dynamicColumnConfig.DynamicItemTitleName].ToString()) + dynamicColumnConfig.AutoColumnStartIndex; // +1 因为 ClosedXML 列从1开始
}
else
{
writeIndex = dynamicColumnConfig.ColumnIdList.IndexOf(iteObjDic[dynamicColumnConfig.DynamicItemTitleId].ToString()) + dynamicColumnConfig.AutoColumnStartIndex ; // +1 因为 ClosedXML 列从1开始
writeIndex = dynamicColumnConfig.ColumnIdList.IndexOf(iteObjDic[dynamicColumnConfig.DynamicItemTitleId].ToString()) + dynamicColumnConfig.AutoColumnStartIndex; // +1 因为 ClosedXML 列从1开始
}

View File

@ -17492,17 +17492,17 @@
</member>
<member name="F:IRaCIS.Core.Application.ViewModel.AccessToDialogueEnum.Question">
<summary>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
质疑
</summary>
</member>
<member name="F:IRaCIS.Core.Application.ViewModel.AccessToDialogueEnum.Consistency">
<summary>
һ<EFBFBD><EFBFBD><EFBFBD>Ժ˲<EFBFBD>
一致性核查
</summary>
</member>
<member name="T:IRaCIS.Core.Application.ViewModel.CopyFrontAuditConfigItemDto">
<summary>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
复制
</summary>
</member>
<member name="T:IRaCIS.Core.Application.ViewModel.SystemNoticeView">

View File

@ -155,7 +155,7 @@ namespace IRaCIS.Core.Application.Service.Common
};
var (memoryStream, fileName) = await ExcelExportHelper.DataExport_NpoiTestAsync(StaticData.Export.TrialQCResult_Export, exportInfo, _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(QCQuestionResult_Export), dynamicColumnConfig: dynamicColumnConfig);
var (memoryStream, fileName) = await ExcelExportHelper.DataExport_ClosedXMLAsync(StaticData.Export.TrialQCResult_Export, exportInfo, _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(QCQuestionResult_Export), dynamicColumnConfig: dynamicColumnConfig);
return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
{
@ -1227,7 +1227,7 @@ namespace IRaCIS.Core.Application.Service.Common
exportInfo.CurrentTime = ExportExcelConverterDate.DateTimeInternationalToString(DateTime.Now, _userInfo.TimeZoneId);
var (memoryStream, fileName) = await ExcelExportHelper.DataExport_NpoiTestAsync(StaticData.Export.TrialSubjectProgressList_Export, exportInfo, /*"", */_commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(SubjectProgressDto));
var (memoryStream, fileName) = await ExcelExportHelper.DataExport_ClosedXMLAsync(StaticData.Export.TrialSubjectProgressList_Export, exportInfo, /*"", */_commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(SubjectProgressDto));
// 使用 ClosedXML 进行二次处理
@ -2717,7 +2717,7 @@ namespace IRaCIS.Core.Application.Service.Common
};
var (memoryStream, fileName) = await ExcelExportHelper.DataExport_NpoiTestAsync(export_Template, exportInfo, _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(AnalysisDynamicCommonExport), criterion.CriterionType, dynamicColumnConfig);
var (memoryStream, fileName) = await ExcelExportHelper.DataExport_ClosedXMLAsync(export_Template, exportInfo, _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(AnalysisDynamicCommonExport), criterion.CriterionType, dynamicColumnConfig);
return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
{
@ -3648,12 +3648,12 @@ namespace IRaCIS.Core.Application.Service.Common
if (inQuery.ReadingExportType == ExportResult.NoneTumorCDISC)
{
(memoryStream, fileName) = await ExcelExportHelper.DataExport_NpoiTestAsync(export_Template, exportInfo, _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(CommonEvaluationExport), criterion.CriterionType, dynamicColumnConfig);
(memoryStream, fileName) = await ExcelExportHelper.DataExport_ClosedXMLAsync(export_Template, exportInfo, _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(CommonEvaluationExport), criterion.CriterionType, dynamicColumnConfig);
}
else
{
(memoryStream, fileName) = await ExcelExportHelper.DataExport_NpoiTestAsync(export_Template, exportInfo, _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(CommonEvaluationExport), criterion.CriterionType, dynamicColumnConfig);
(memoryStream, fileName) = await ExcelExportHelper.DataExport_ClosedXMLAsync(export_Template, exportInfo, _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(CommonEvaluationExport), criterion.CriterionType, dynamicColumnConfig);
}