Performance when loading Excel file

Posted by: zsurdel on 8 September 2017, 2:30 pm EST

  • Posted 8 September 2017, 2:30 pm EST

    <P>Hello - </P>
    <P>We are using FarPoint to open an existing Excel file that contains several sheets each with rather involved calculations. The file is opened using OpenExcel(fileName) method. A new tab was introduced in our file that increased the time it takes to execute this method from less than a minute to over 9 minutes. </P>
    <P>When opened in a designer, the file opens with no noticable delay. This delay is unacceptable from the user perspective. </P>
    <P>I attempted to turn off automatic formula evaluation in the file itself - no help. We tried to rewrite some of the calculations. I tried using the designer to save the file as XML but that saved version could not be opened by the designer itself, let alone programatically. Nothing I tried helped speed up the process of loading the file into the spread. This is now a critical issue that we need to address ASAP.</P>
    <P>Any help would be greatly appreciated.</P>
    <P>Thank you</P>
  • Replied 8 September 2017, 2:30 pm EST

    <p>Hello,</p><p>We would need to have a look at the excel file in order to replicate the issue at our end. Could you please post that excel file?</p><p> </p><p>Thanks,</p><p> </p>
  • Replied 8 September 2017, 2:30 pm EST

    <P>I am attaching a stripped-down version of the file. </P>
  • Replied 8 September 2017, 2:30 pm EST

    <p>Hello,</p><p>I opened the excel file using the following argument with OpenExcel () method and it opened up the file in a flash.</p><p> fpSpread1.OpenExcel("D:\\AAV_TEST.xls", FarPoint.Excel.ExcelOpenFlags.DoNotRecalculateAfterLoad  );  </p><p>I see that it is taking time in calculating all the formulas.Please try the same and let me know if that helps.</p><p> </p><p>Thanks,</p><p> </p><p> </p>
  • Replied 8 September 2017, 2:30 pm EST

    <P>You are right, this makes the opening of the file faster. Unfortunately, this does not solve my problem.</P>
    <P>After I load the file, I then populate it with some values and read out numbers that it produced. </P>
    <P>For the results to get calculated, I need to call LoadFormulas (results are not recalculated otherwise) - if I skip loading formulas originally, it is this method call that will now take 8 minutes.</P>
    <P>Is there any way to speed this up?</P>
    <P>Thank you</P>
  • Replied 8 September 2017, 2:30 pm EST

    <p>Hello,</p><p>Loading the excel file is not taking time, it is the Formulas which are making the process really slow, which is proved by the code,</p><p>   FpSpread1.OpenExcel("D:\AAV_TEST.xls", FarPoint.Excel.ExcelOpenFlags.DoNotRecalculateAfterLoad)<br>You may turn the AutoCalculation On later using :<br></p><p> FpSpread1.ActiveSheet.AutoCalculation = True  </p><p>I will further see if we can make the processing better with the formulas also.</p><p> </p><p>Thanks,<br></p><p> </p>
  • Replied 8 September 2017, 2:30 pm EST

    <P>I agree - it is the formulae that cause the problem. The spreadsheet has no issues when opened in Excel or the designer of FarPoint grid. </P>
    <P>Using your approach (setting AutoCalculation to true after the file is loaded into grid) only delays the performance hit. </P>
    <P>Please let me know if there is anything else we can try.</P>
  • Replied 8 September 2017, 2:30 pm EST

    <p>Hello,</p><p>The problem appears to be caused by many invalid arguments specified in the formulas.  The calc engine is throwing many InvalidCastExceptions and FormatExceptions during the recalculation, and that slows down the load significantly.</p><p>The Excel file is setup such that it generates a large number of #VALUE! errors in the non-taken branches of the IF statements.  Since our calc engine evaluates the non-taken branches and since our calc engine uses exceptions to handle the #VALUE! errors, our calc engine hits a real performance bottle neck in this rare real world example.<br><br> The long term fix would be to implement the IF/CHOOSE functions as branch statements and to stop using InvalidCastException for handling #VALUE! errors.<br><br>I possible short term fix might be to modify the operators (e.g. +, -) to check for "" and return #VALUE! error prior to calling CalcConvert.ToXxx method.  This would avoid many of the InvalidCastException exceptions encountered in this specific Excel file.</p><p> </p><p>Thanks,</p><p> </p><p> </p><p> </p>
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels