c# - Multiple pivottable creation using EPPlus -


im starting use epplus lib create "complex" workbooks via c#, , ran trouble while trying create 2 pivot tables.

the first 1 creates fine, when try create second 1 doesnt throw exceptions when try open worknook using excel says

"excel found unreadable content in 'myworkbook.xlsx'. want recover contents of workbook? if trust source of workbook, clickyes"

and when press 'yes':

repair log -> removed feature: pivottable report /xl/pivottables/pivottable2.xml part (pivottable > view) removed records: workbook properties /xl/workbook.xml part (workbook) repaired records: workbook properties /xl/workbook.xml part (workbook)

here's code build:

createpivottable("pivot1", "pivot1", rng1); createpivottable("pivot2", "pivot2", rng2);     public void createpivottable(string pivotsheet, string pivotname, excelrangebase srcrange)     {         if (m_wb.worksheets[pivotsheet] != null)             m_wb.worksheets.delete(pivotsheet);          var ws = m_wb.worksheets.add(pivotsheet);          var pivot = ws.pivottables.add(ws.cells["a1"], srcrange, pivotname);                  } 

any ideas?

thanks!

what wrong , didnt put in question was reopening workbook on step before, this:

    createpivottable("pivot1", "pivot1", rng1);     save();     createpivottable("pivot2", "pivot2", rng2);      private void save()     {         m_writer.save();         m_writer.openworkbook ();     } 

and since save method of epplus closes workbook, program lost sort of reference or got lost info.

in short, use epplus correctly, should write u need before saving , closing workbook, not reopen.

thank you.


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -