Free Support Forum - aspose.com

Table Widths

The application I am currently working on uses ASPOSE heavily for reporting. To make my job easier I have a class which has a set of reporting functions. The functions I use to create tables works fine, but now when I have 7 columns, and lots of text in the 7th column the table goes to the right off the page. I tried setting wrap on the cells, but it still doesn’t work. Below are the functions I am using:

public void AddTableHeaders(DocumentBuilder builder, string[] headers)
{
int leftIndent = (int)builder.ParagraphFormat.LeftIndent;
builder.RowFormat.Borders.LineStyle = LineStyle.Single;
builder.RowFormat.Borders.LineWidth = 1;
builder.RowFormat.Borders.Color = colTableBorder;
builder.RowFormat.LeftIndent = leftIndent + 5;

double headerWidthPercentage = 100 / headers.Length;
builder.RowFormat.Height = 20;
builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;

double width = (builder.PageSetup.PageWidth * headerWidthPercentage) / 100;
builder.CellFormat.Width = width;

foreach (string str in headers)
{
builder.InsertCell();
builder.ParagraphFormat.LeftIndent = 0;
builder.ParagraphFormat.SpaceBeforeAuto = false;
builder.ParagraphFormat.SpaceAfterAuto = false;
builder.Font.Bold = true;
builder.Font.Color = colTableHeaderForeground;
builder.CellFormat.Shading.BackgroundPatternColor = colTableHeaderBackground;
builder.Write(str == null ? String.Empty : str);
}

builder.EndRow();
}

public void InsertTableCell(DocumentBuilder builder, string cellvalue, int counter)
{
builder.InsertCell();
builder.Bold = false;
builder.Font.Color = colTextNormalForeground;
builder.CellFormat.Shading.BackgroundPatternColor = (counter % 2 == 0 ? colTableRowNormalBackground : colTableRowAlternateBackground);
builder.Write(cellvalue == null ? String.Empty : cellvalue);
}

I call StartTable() create the headers, then insert my cells, end the row, then end the table when complete. Is there a reason why the last column is going to the right of the page and not wrapping?

Thanks.

Hi

Thanks for your request. Also, please attach the document with problem. Then I will investigate problem and try to solve it.

Best regards.

I think you should be using something like

builder.PageSetup.PageWidth-(builder.PageSetup.MarginLeft+builder.PageSetup.MarginRight)

Can't remember if the syntax for margin property is correct here, but you get the idea :)

Cheers,
Jason