what is the most efficient way to save only the sheets which were used for the current report? Normaly we are delivering an Excel file with a collection of report templates for different purposes. Currently I implemented a logic which stores the sheet names of the sheets which were used for a report, and remove all other sheets out of the workbook before saving it.
Is that the way you would also suggest, or is there any better idea?
I think deleting the sheets manually should be a good approach in this situation, yes. But delete them before running the report, not before saving them.
I mean, if you have 10 sheets: Sheet1... Sheet10, and you only care about Sheet7, it makes no sense to run the report in the full 10 sheets (basically running all the 10 reports) so then you delete 9 of those. It is better to remove the sheets before running the report, and run it only in Sheet7.
Right, thats what I did, deleting not used sheets, running the report and saving it. I finally found the
Xlsfile.InsertAndCopySheets()
method. Now I'm creating a new xls file, copy only the sheets the report is using and then running the report. Result is the same, but somehow I like the copy variant over deleting sheets. Furthermore, deleting a sheet is not possible when the sheet contains a macro.