Hi,
I'm kind of lost here. I try to open an excel template with a pre-definied table in it. Find it attached.
Then I try to open it and select the table as shown in your docs and in my code below.
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
//Create a workbook
IWorkbook workbook = application.Workbooks.Open(template, ExcelOpenType.Automatic);
IWorksheet worksheet = workbook.Worksheets[0];
//Accessing first table in the sheet
IListObject table = worksheet.ListObjects[0];
However I stuck to simply add a new row to it?
I loop to my data and increase the row count by 1 for each item.
The data looks fine in the export, however the table stays at 1 data row.
//Go to list
for (int i = 0; i < calcs.Count; i++)
{
int Row = Convert.ToInt32(Settings.StartRow);
string Col = Settings.StartColumn;
// Pos
worksheet.Range[string.Format("{0}{1}", Col ,Row + i)].Number = i +1 ;
// Description
StringBuilder sb = new StringBuilder();
sb.AppendLine(calcs[i].Name);
/*
sb.AppendLine(string.Format("Volume: {0} | Time: {1}",
Convert.ToDouble(calcs[i].Volume),
Convert.ToDouble(calcs[i].CalculatedPrintTime))
);
*/
Col = GetNextColumn(Col, 1);
worksheet.Range[string.Format("{0}{1}", Col, Row + i)].Text = sb.ToString();
// Quantity
Col = GetNextColumn(Col, 1);
worksheet.Range[string.Format("{0}{1}", Col, Row + i)].Number = Convert.ToDouble(calcs[i].Quantity);
worksheet.Range[string.Format("{0}{1}", Col, Row + i)].NumberFormat = "0";
// Single
Col = GetNextColumn(Col, 1);
worksheet.Range[string.Format("{0}{1}", Col, Row + i)].Number = (Convert.ToDouble(calcs[i].Total) / (Convert.ToDouble(calcs[i].Quantity)));
worksheet.Range[string.Format("{0}{1}", Col, Row + i)].NumberFormat = "€.00";
// Total
Col = GetNextColumn(Col, 1);
worksheet.Range[string.Format("{0}{1}", Col, Row + i)].Number = Convert.ToDouble(calcs[i].Total);
worksheet.Range[string.Format("{0}{1}", Col, Row + i)].NumberFormat = "€.00";
if (i < calcs.Count - 1)
{
// add new row here?
}
Also I want to currency formated using the current currency symbol from the OS.
Thanks for helping out!
Best,
Andreas
Attachment:
export_template_428740d1.zip