How to redefine column headings in Aspose table?


#1


1. we build a datatable and use english column names
2. we then import this datatable into an aspose table
3. we now want to display this aspose table with GERMAN column headings

How do we change the column headings after the aspost table has imported the datatable?

e.g. something like this:

Private m_Table As Table = New Table
m_Table.Columns(0).Header = "Gruppe"
m_Table.Columns(1).Header = "Fehlermeldung"

I tried changing the CAPTIONS in the DataTable columns before it was imported, but the Aspose table still took the column NAMES from the datatable instead of the captions.

Thanks,
Edward


#2

Dear Edward,

Thank you for considering Aspose.

I have tested tried changing the caption of column and it worked. Here is my code:

[C#]
DataTable dt = new DataTable(“Employee”);
dt.Columns.Add(“Employee_ID”,typeof(Int32));
dt.Columns.Add(“Employee_Name”,typeof(string));
dt.Columns.Add(“Gender”,typeof(string));
DataRow dr = dt.NewRow();
dr[0] = 1;
dr[1] = “John Smith”;
dr[2] = “Male”;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = 2;
dr[1] = “Mary Miller”;
dr[2] = “Female”;
dt.Rows.Add(dr);

Pdf pdf1 = new Pdf(@“e:\projects\CSharp\customer\Aspose.Pdf.lic”);

Section sec1 = pdf1.Sections.Add();

Table tab1 = new Table();
sec1.Paragraphs.Add(tab1);
tab1.ColumnWidths = “40 100 100 100”;
tab1.DefaultCellBorder = new BorderInfo((int)BorderSide.All,0.1F);

dt.Columns[0].Caption = “aaa”;

tab1.ImportDataTable(dt,true,0,1,3,3);

Row row1 = tab1.Rows[0];
foreach(Cell curCell in row1.Cells)
curCell.BackgroundColor = new Color(“Blue”);

pdf1.Save(“e:/temp/test.pdf”);

[VisualBasic]
Dim dt As DataTable = New DataTable(“Employee”)
dt.Columns.Add(“Employee_ID”, System.Type.GetType(“System.Int32”))
dt.Columns.Add(“Employee_Name”, System.Type.GetType(“System.String”))
dt.Columns.Add(“Gender”, System.Type.GetType(“System.String”))
Dim dr As DataRow = dt.NewRow()
dr(0) = 1
dr(1) = “John Smith”
dr(2) = “Male”
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = 2
dr(1) = “Mary Miller”
dr(2) = “Female”
dt.Rows.Add(dr)

Dim pdf1 As Pdf = New Pdf(“e:\projects\CSharp\customer\Aspose.Pdf.lic”)

Dim sec1 As Section = pdf1.Sections.Add()

Dim tab1 As Table = New Table()
sec1.Paragraphs.Add(tab1)
tab1.ColumnWidths = “40 100 100 100”
tab1.DefaultCellBorder = New BorderInfo(BorderSide.All, 0.1F)

dt.Columns(0).Caption = “aaa”

tab1.ImportDataTable(dt, True, 0, 1, 3, 3)

Dim row1 As Row = tab1.Rows(0)
Dim curCell As Cell
For Each curCell In row1.Cells
curCell.BackgroundColor = New Color(“Blue”)
Next

pdf1.Save(“e:/temp/test.pdf”)