c# - File corrupted simply by opening and saving with no changes -


working on code update spreadsheet noticed isolated act of opening spreadsheet , saving corrupts it, resulting in message "we found problem content in''. want try recover as can?"

this can replicated following code

fileinfo excelfile = new fileinfo("mysheet.xlsm"); using (excelpackage excel = new excelpackage(excelfile)) {     excel.save(); } 

the resulting file shrinks around 3mb 2mb in process.

seems should pretty straight forward must missing crucial.

discaimer: isn't answer, want post code

i've tried reproduce problem, no luck. steps follows:

i've created spreadsheet manually in excel 2010. text in cell a1 of sheet1 reads "hello". i've added code module in macro editor (alt-f11) following code:

option explicit  sub foo()      msgbox "hello world", vbokonly, "foo!"  end sub 

i saved macro-enabled spreadsheet (c:\temp\book1.xlsm)

in visual studio created c# console app , added epplus package nuget. main method looks this:

static void main(string[] args) {     using (var pck = new excelpackage(new fileinfo(@"c:\temp\book1.xlsm")))     {         pck.save();     } } 

when debug executes without issue.

have checked permissions on folder you're saving , forced refresh of epplus package?


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -