forked from ddrilling/AsbCloudServer
CS2-74: Changed using NPOI library to ClosedXML
This commit is contained in:
parent
845f1f0fb1
commit
059475e96a
@ -57,15 +57,14 @@ namespace AsbCloudInfrastructure.Services
|
||||
.Where(f => f.Name != resultFileName)
|
||||
.Select(f => fileService.GetUrl(f));
|
||||
|
||||
var resultExcelPath = Path.Combine(fileService.RootPath,
|
||||
$"{idWell}", $"{idFileCategoryDrillingProgram}",
|
||||
resultFileName);
|
||||
var tempResultFilePath = Path.Combine(Path.GetTempPath(), "drillingProgram", resultFileName);
|
||||
|
||||
UniteExcelFiles(fileNames, resultExcelPath);
|
||||
UniteExcelFiles(fileNames, tempResultFilePath);
|
||||
|
||||
return await fileService.SaveAsync(idWell, null, idFileCategoryDrillingProgram,
|
||||
resultExcelPath, null, token)
|
||||
.ConfigureAwait(false);
|
||||
var fileInfo = await fileService.MoveAsync(idWell, null, idFileCategoryDrillingProgram,
|
||||
resultFileName, tempResultFilePath, token).ConfigureAwait(false);
|
||||
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
private static void UniteExcelFiles(IEnumerable<string> excelFilesNames, string resultExcelPath)
|
||||
@ -74,12 +73,25 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
const int maxAllowedColumns = 256;
|
||||
|
||||
foreach (var excelFileName in excelFilesNames)
|
||||
var filteredFileNames = excelFilesNames.Distinct();
|
||||
|
||||
foreach (var excelFileName in filteredFileNames)
|
||||
{
|
||||
using var sourceExcelFile = new XLWorkbook(excelFileName, XLEventTracking.Disabled);
|
||||
|
||||
foreach (var sheet in sourceExcelFile.Worksheets)
|
||||
{
|
||||
var newSheetName = sheet.Name;
|
||||
int index = 1;
|
||||
|
||||
if (resultExcelFile.Worksheets.Contains(newSheetName))
|
||||
{
|
||||
var suffix = $"_{index++}";
|
||||
if (newSheetName.Length + suffix.Length >= 31)
|
||||
newSheetName = sheet.Name.Substring(0, (31 - suffix.Length));
|
||||
newSheetName += suffix;
|
||||
}
|
||||
|
||||
var imagesInfos = sheet.Pictures.Select(p => new ImageInfo
|
||||
{
|
||||
Id = p.Id,
|
||||
@ -93,7 +105,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
if (sheet.Columns().Count() > maxAllowedColumns)
|
||||
{
|
||||
var resultSheet = resultExcelFile.Worksheets.Add(sheet.Name);
|
||||
var resultSheet = resultExcelFile.Worksheets.Add(newSheetName);
|
||||
|
||||
var rngData = GetCellsRange(sheet);
|
||||
|
||||
@ -114,7 +126,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
RemovePicturesFromSheet(sheet);
|
||||
|
||||
var resultSheet = sheet.CopyTo(resultExcelFile, sheet.Name);
|
||||
var resultSheet = sheet.CopyTo(resultExcelFile, newSheetName);
|
||||
|
||||
CopyImagesToAnotherSheet(imagesInfos, resultSheet);
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Host=192.168.1.70;Database=postgres;Username=postgres;Password=q;Persist Security Info=True",
|
||||
"DefaultConnection": "Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True",
|
||||
"ServerConnection": "Host=192.168.1.70;Database=postgres;Username=postgres;Password=q;Persist Security Info=True",
|
||||
"LocalConnection": "Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True"
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user