mercredi 25 février 2015

EPPlus with a template is not working as expected

I am currently using EPPlus project in order to manipulate some .xlsx files. The basic idea is that I have to create a new file from a given template.


But when I create the new file from a template, all calculated columns in the tables are messed up.


The code I am using is the following:



static void Main(string[] args)
{
const string templatePath = "template_worksheet.xlsx"; // the path of the template
const string resultPath = "result.xlsx"; // the path of our result

using (var pck = new ExcelPackage(new FileInfo(resultPath), new FileInfo(templatePath))) // creating a package with the given template, and our result as the new stream
{
// note that I am not doing any work ...
pck.Save(); // savin our work
}
}


For example for a .xlsx file (that have a table with 3 columns, the last one is just the sum of the others) the program creates a .xlsx file where the last column have the same value (which is correct only for the first row) in all rows.


The following images shows the result:


Table in the template Table in the result


Now the questions are: What is going on here ? Is my code wrong ? How can I accomplish this task without that unexpected behavior ?


Aucun commentaire:

Enregistrer un commentaire