0

I have developed a windows form project that is export large date in excel. Sometimes worksheet.save() method takes 1 hour or infitine time. I think it stay locked, but I don't know why. Does anyone have any ideas to solve this?

    ...
    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);
BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117
RockOnGom
  • 3,893
  • 6
  • 35
  • 53
  • Have you been able to reproduce it? Do you know what line it happens on? Have you investigated the `foreach` loop to see how much data it is spinning over? – Jeff B Dec 30 '13 at 19:09
  • 1
    Most of the time it is because a blocking messagebox is raised by excel and since you don't have an excel window open you don't see it. Try debugging with an empty excel window open, because excel shares it's main window with all documents you could benefit from that. Side note: maybe perhaps you could try to open the doc with excel when it's 'locking', because it could give you the messagebox then. – Silvermind Dec 30 '13 at 19:40
  • @JeffBridgman "worksheetPart.Worksheet.Save();" ıt happens here,ın thıs lıne.There ıs no problem ın foreach loop.Sometımes ın 20k,sometımes ın 100k,but sometımes ıt doesn t happen ın 150k. – RockOnGom Dec 30 '13 at 20:20
  • Hi, did you ever manage to fix this issue? Cause I have the same problem but only with some files. – Luis Ferrao Feb 11 '15 at 16:23

0 Answers0