我开发了一个windows表单项目,它在excel中导出大日期。有时,worksheet.save()方法需要1小时或无限时间。我认为它保持锁定,但我不知道为什么。有没有人有任何想法来解决这个问题?
...
FileInfo temp_excel_file = new FileInfo(Path.Combine(ConfigFile.ConfigsPaths["ExcelRaporFolder"], "temp", "Rakip.xlsm"));
rapor_file = new FileInfo(Path.Combine(ConfigFile.ConfigsPaths["ExcelRaporFolder"], "excel", FileName + ".xlsm"));
File.Copy(temp_excel_file.FullName, rapor_file.FullName);
Log.LogYaz(rapor_file.Name + "-Excell Açılıyor..");
SpreadsheetDocument myDoc = SpreadsheetDocument.Open(rapor_file.FullName, true);
IEnumerable<Sheet> sheets = myDoc.WorkbookPart.Workbook.Descendants<Sheet>();
WorksheetPart worksheetPart = (WorksheetPart)myDoc.WorkbookPart.GetPartById(sheets.Skip(1).First().Id);
SheetData sheetData = worksheetPart.Worksheet.Elements<SheetData>().First();
Log.LogYaz(rapor_file.Name + "-Rowlar Yaziliyor..");
uint row = 2;
Stopwatch swLoadTime = new Stopwatch();
swLoadTime.Start();
foreach (var row_index in filtered_data)
{
....
sheetData.AppendChild(Utils.CreateRow(row, 0, cell_data));
row++;
}
swLoadTime.Stop();
string loadRowTime = swLoadTime.Elapsed.ToString();
Log.LogYaz("RowsWasLoaded -" + FileName.ToString() + Environment.NewLine + " Load Row Time:" + loadRowTime);
swLoadTime.Reset();
swLoadTime.Start();
worksheetPart.Worksheet.Save();
myDoc.Close();
myDoc = null;
swLoadTime.Stop();
Log.LogYaz("RaporYazildi -" + FileName.ToString() + Environment.NewLine + " Load Row Time:" + loadRowTime + Environment.NewLine + " Save File Time:" + swLoadTime.Elapsed);