How to format table?

  1. I finally got the ImportDataTable method to work with the following code.

    2. Now I want to:
    a. remove the blank line at the top (why is it there, it is not in the datatable)
    b. right-align one of the columns
    c. add a different font name and size to the headers

    How do I format the table like this?

    Thank you,

    Edward

I forgot to post my code for how I am making my table that I need to format, here it is:

Pdf pdf = new Pdf();

//section
Section section = pdf.Sections.Add();

//define margins
section.PageInfo.Margin.Top = m_TopMargin;
section.PageInfo.Margin.Bottom = m_BottomMargin;
section.PageInfo.Margin.Left = m_LeftMargin;
section.PageInfo.Margin.Right= m_RightMargin;
section.IsLandscape = true;

//get datatable
DataTable dt = DataLayer.GetDataTable(“SELECT CustomerID,CompanyName,Address,City,Country,Phone,Score FROM Customers WHERE Country=‘Germany’ ORDER BY CompanyName”);

//table
Aspose.Pdf.Table table = new Aspose.Pdf.Table();

//it seems you have to define the default cell information RIGHT AFTER instantiating the table
table.DefaultCellBorder = new BorderInfo((int)BorderSide.All,1F);
table.DefaultCellPadding.Bottom = 3;
table.DefaultCellPadding.Top = 3;
table.DefaultCellPadding.Left = 3;
table.DefaultCellPadding.Right= 3;
table.DefaultCellTextInfo.FontName = “Arial”;
table.DefaultCellTextInfo.FontSize = 8;

table.ColumnWidths = “100 150 100 100 50 50 75”;
table.ImportDataTable(dt,true,1,0);
table.Border = new BorderInfo((int)(BorderSide.All),1F);
section.Paragraphs.Add(table);

//save the file
string fileName = HttpContext.Current.Server.MapPath(“pdf/GridReport.pdf”);
pdf.Save(fileName);

So I am trying to edit the fonts of the header row, I use this code:

//test: header row bold
Cells headerCells = table.Rows[1].Cells;
foreach(Cell cell in headerCells)
{
cell.Paragraphs…
}

Do I have to then pack all the paragraphs out of all the cells in the row?
And then pack all the segments out of the paragraphs out of the rows?
And then change the font of the rows?

Or is there is an EASY way to do it like this:

table.Rows[1].FontName = “Verdana”;
table.Rows[1].FontSize = 14;

That would be nice.

Thanks,
Edward

Dear Edward,

Thanks for your consideration.

1) I have fixed the blank line bug, please download hot fix 1.6.4. If it still won’t work, please let me know.

2) It’s really not convenient to set row or column format using current API. Your suggest is very nice. I will add a new property TextInfo into the Row class and a properties array ColumnTextInfo[] to Table class. So you will be able to set row and column format like this:

table.Rows[1].TextInfo.FontName = “Verdana”;
table.ColumnTextInfo[1].Alignment = AlignmentType.Right;

  1. I downloaded the hotfix 1.6.4.

  2. It is a zip file with two files in it: Aspose.Pdf.dll and Aspose.Pdf.xml

  3. I deleted the reference to the Aspose.pdf.dll out of my VS.NET solution and then rereferenced the new .dll that I downloaded.

  4. When I recompile my code, I still get the blank line at the top of the table.

  5. What am I supposed to do with the Aspose.Pdf.xml?

  6. What else do I need to do so that the blank-line-bug is fixed?

Thanks,

Edward

Dear Edward,

Thanks for your consideration.

1) I notice that you use this line:
table.ImportDataTable(dt,true,1,0);
You use 1 as the first line to import data. But the row number begins at 0. So there is a blank.

2) Please refer to thread Intellisense XML file for the usage of Aspose.Pdf.xml.

Excellent:

table.ImportDataTable(dt,true,0,0);

made the blank line go away, Thanks!

Edward

Dear Edward,

Thanks for your consideration.

Please download hot fix 1.6.5 at thread New Release 1.6.0.0 and Its Hot Fixes.