Hi there,
Below is a code spinet (in C#) for creating two adjacent tables.
Please note that the first table has no rows.
The code runs fine if (any) single table is generated only,
that is if you comment out code for “topTable” or “bottomTable” the resulting Excel file is fine.
However, if both tables are created then styling is messed up and the file becomes corrupt.
(It still opens though just style is bad).
Is the problem caused by the fact that the “topTable” has not rows?
Is there any way to achieve this (that is, two adjacent tables with one of them without rows) by using different syntax?
Of course I could “simulate” a table header manually in case there are no rows, but I would rather
use table style enumeration via “TableStyleType” property.
Thank you for your help.
Code:
Workbook wb = new Workbook();
Worksheet ws = wb.Worksheets[0];
//topTable
//ws.Cells[2, 2].PutValue("First Name");
//ws.Cells[2, 3].PutValue("Last Name");
//ws.Cells[2, 4].PutValue("State");
//var topTable = ws.ListObjects[ws.ListObjects.Add(2, 2, 2, 4, true)];
//topTable.TableStyleType = TableStyleType.TableStyleLight8;
//bottomTable
ws.Cells[3, 2].PutValue("First Name");
ws.Cells[3, 3].PutValue("Last Name");
ws.Cells[3, 4].PutValue("State");
ws.Cells[4, 2].PutValue("John");
ws.Cells[4, 3].PutValue("Doe");
ws.Cells[4, 4].PutValue("USA");
var bottomTable = ws.ListObjects[ws.ListObjects.Add(3, 2, 4, 4, true)];
bottomTable.TableStyleType = TableStyleType.TableStyleLight8;
var myDir = @"yourDirHere";
var aformat = Aspose.Cells.SaveFormat.Xlsx;
wb.Save(myDir + "TestAsPoseExcel_5.xlsx", aformat);