Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize calculation chain generation #436

Closed
1 of 3 tasks
lzeitz opened this issue Aug 9, 2017 · 11 comments
Closed
1 of 3 tasks

Optimize calculation chain generation #436

lzeitz opened this issue Aug 9, 2017 · 11 comments
Labels
enhancement Feature already exists, but should be enahanced.
Milestone

Comments

@lzeitz
Copy link

lzeitz commented Aug 9, 2017

Do you want to request a feature or report a bug?

  • Bug
  • Feature

Version of ClosedXML

e.g. 0.87.1

What is the current behavior?
Calling the workbook save takes 2 minutes and 50 seconds for a 3.5 MB file. I have only modified 2 cells on one worksheet. Saving within Excel 2016 takes under 5 seconds on the file.
If the current behavior is a bug, please provide the steps to reproduce and
if possible a minimal demo of the problem with a sample spreadsheet.

I have a large excel file with many tabs, some of which contain images. I have a hidden tab that contains metadata that I modify during file upload by setting the values for 2 fields on the sheet. When I am done, I call workbook.Save(). This takes an extremely long time.
What is the expected behavior or new feature?
Saving a workbook should be on the order of a file save within Excel.
Did this work in previous versions of our tool? Which versions?

  • I attached a sample spreadsheet. (You can drag files on to this issue)

Code to reproduce problem:

public void Main()
{
    // Where possible, post full code to reproduce your issue that adheres to:
    // - Fully runnable. I should be able to copy and paste this code into a 
    //   console application and run it without having to edit it much.
    // - Declare all your variables (this follows from the previous point)
    // - The code should be a minimal code sample to illustrate issue. The code 
    //   samples on the wiki are good examples of the terseness that I want. Don't
    //   post your full application.
}
@igitur
Copy link
Member

igitur commented Aug 10, 2017

Too vague. If you can identify a certain piece of code that can be optimised, let me know.

@igitur igitur closed this as completed Aug 10, 2017
@lzeitz
Copy link
Author

lzeitz commented Aug 10, 2017

I am using version 0.87.0 of ClosedXml.

I found that the piece of code that is taking a long time is GenerateCalculationChainPartContent.

Would it be possible to skip regenerating this step as all I want to do is save? Our workbooks are downloaded and filled in by our users. All calculations of theirs have already been made when they closed and saved the workbooks and we do not need to recalculate formulas for this reason. The workbooks have formulas that span tabs and can traverse up to 15 tabs in some cases.

@igitur
Copy link
Member

igitur commented Aug 10, 2017

Attach a sample file for me to inspect.

@igitur igitur reopened this Aug 10, 2017
@lzeitz
Copy link
Author

lzeitz commented Aug 10, 2017

@lzeitz lzeitz closed this as completed Aug 10, 2017
@lzeitz lzeitz reopened this Aug 10, 2017
@lzeitz
Copy link
Author

lzeitz commented Aug 10, 2017

Attached a file
Note - my files are xlsm but I have saved as an xlsx to remove the macros

@igitur igitur changed the title ClosedXml Save takes too long Optimize calculation chain generation Aug 11, 2017
@igitur igitur added enhancement Feature already exists, but should be enahanced. and removed wontfix labels Aug 11, 2017
@igitur
Copy link
Member

igitur commented Aug 11, 2017

Try the build at https://ci.appveyor.com/project/Pyropace/closedxml/build/0.8.447/artifacts - by default it should be better.

If you really want to skip the generation of the calculation chain, you can do:

workbook.SaveAs(file, new SaveOptions { GenerateCalculationChain = false });

@lzeitz
Copy link
Author

lzeitz commented Aug 11, 2017

I attempted to use the build you specified with a .Save(false, false) and with the suggestion provided above, but all formulas on the Source Cash Flow Tab were garbled when saving the workbook. Almost every column in that tab had its formula changed. For example, the formula in T13 should be
=SUMIF($C$62:$C$1024,$C13,T$62:T$1024)

Instead, it is
=SUMIF($C$62:$C$1024,$C13,E$62:E$1024)

I can see that the template I tried to scrub lost formulas before it was uploaded. I am providing a clean empty template since I am experiencing the slowness on write.
Clean Template.xlsx

The time to save dropped to approximately 20 seconds (down from 1 minute 20 seconds) on my computer and 40 seconds (down from 2 minutes and 50 seconds) on our development server (not sure why the difference is there).

@igitur
Copy link
Member

igitur commented Aug 14, 2017

Yeah, I introduced a bug in shared formula parsing. Fixed now. Try the artifacts at https://ci.appveyor.com/project/Pyropace/closedxml/build/0.8.449/artifacts

@igitur igitur modified the milestones: v0.89, v0.90 Sep 8, 2017
@igitur igitur closed this as completed Sep 22, 2017
@igitur
Copy link
Member

igitur commented Oct 6, 2017

https://www.nuget.org/packages/ClosedXML/0.90.0-beta2 is released and should include the fix for this issue.

@csarcor15
Copy link

how macros are generated?

@igitur
Copy link
Member

igitur commented Sep 12, 2018

@csarcor15 Macros are not supported yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature already exists, but should be enahanced.
Projects
None yet
Development

No branches or pull requests

3 participants