thanks for the help, i am getting an exception: Error saving file C:\U..... {"Object reference not set to an instance of an object."}
StackTrace: at OfficeOpenXml.ExcelPackage.Save() at MINAG.SMEA.Business.ExcelBusinessService.CreateTableExcel(Decimal surveyId) in c:\Users\luciano\Desktop\New folder\implementation\MINAG.SMEA.Business\ExcelBusinessService.cs:line 2048
(only that on stack trace)
My current code is:
FileInfo newFile = new FileInfo(file);
ExcelPackage excPck = new ExcelPackage(newFile);
foreach (SURVEY_BASE_TABLE_LIST item in survey.SURVEY_BASE_TABLE_LIST)
{
BASE_TABLE_LIST table = item.BASE_TABLE_LIST;
Int32 limit = table.CODE.Length;
if (limit > 31)
limit = 31;
string dynamicRangeFormula = "OFFSET('" + table.CODE.Substring(0, limit) + "'!$A$1;0;0;COUNTA('" + table.CODE.Substring(0, limit) + "'!$A$1:$A$1000)+1;COUNTA('" + table.CODE.Substring(0, limit) + "'!$1:$1))";
var ws = excPck.Workbook.Worksheets.Add("Pivot_" + table.CODE);
ExcelNamedRange newRange = new ExcelNamedRange(table.CODE.Substring(0, limit), null, ws, "C3", excPck.Workbook.Names.Count)
{
Formula = dynamicRangeFormula
};
var excelPivot = ws.PivotTables.Add(ws.Cells["A1"], newRange, "Pivot_" + table.CODE);
}
excPck.Save();
Any ideas?