Sign In  Sign Up Live-Chat

PDF: Nested tables and columnSpan

Last post 09-16-2007, 6:11 PM by Hans.firefox. 6 replies.
Sort Posts: Previous Next
  •  08-23-2007, 7:16 AM 91994

    PDF: Nested tables and columnSpan

    Hi
    I'm trying to create nested tables where the inner table is supposed to span over two column. The problem is that the data in the inner table (from a DataTable) doesn't span over both columns even though the cell it is located in spans over both columns.
    This is my code:
    Aspose.Pdf.Table layoutTab = new Aspose.Pdf.Table(sec1);
    layoutTab.ColumnWidths = "50% 50%";
    layoutTab.ColumnAdjustment = ColumnAdjustmentType.Customized;
    layoutTab.Rows.Add().Cells.Add();
    layoutTab.Rows[0].Cells[0].ColumnsSpan = 2;

    Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table(layoutTab.Rows[0].Cells[0]);
    tab1.ColumnWidths = "100%";
    tab1.ColumnAdjustment = ColumnAdjustmentType.AutoFitToContent;

    tab1.Rows.Add().Cells.Add().Paragraphs.Add(new Aspose.Pdf.Text("hello world"));
               
    Aspose.Pdf.Table tab2 = new Aspose.Pdf.Table(tab1.Rows.Add().Cells.Add());
    tab2.ImportDataTable(myDT, true, 0, 0);
    tab1.Rows[1].Cells[0].Paragraphs.Add(tab2);

    layoutTab.Rows[0].Cells[0].Paragraphs.Add(tab1);
    sec1.Paragraphs.Add(layoutTab);


    Then layoutTab.Rows[0].Cells[0] acctually spans over two cells, but the data in tab2 fits in to the size of only one cell and the second cell is empty.

    What am I missing?

    Regards,
     Sara

     
  •  08-23-2007, 10:22 AM 92033 in reply to 91994

    Re: PDF: Nested tables and columnSpan

    Attachment: Present (inaccessible)

    Hi,

    Thank you for considering Aspose.

    I have checked with the following code and it works for me. Please find attached PDF generated by the code below:

    [C#]

                Aspose.Pdf.Pdf pdf1 = new Aspose.Pdf.Pdf();
                Aspose.Pdf.Section sec1 = pdf1.Sections.Add();
                Aspose.Pdf.Table layoutTab = new Aspose.Pdf.Table(sec1);
                layoutTab.DefaultCellBorder = new BorderInfo((int)BorderSide.All);
               
                layoutTab.ColumnWidths = "50% 50%";
                layoutTab.ColumnAdjustment = ColumnAdjustmentType.Customized;
                layoutTab.Rows.Add().Cells.Add();
                layoutTab.Rows[0].Cells[0].ColumnsSpan = 2;

                DataTable myDT = new DataTable();
                DataColumn dc = new DataColumn("Col1");
                DataColumn dc1 = new DataColumn("Col2");
                myDT.Columns.Add(dc);
                myDT.Columns.Add(dc1);

                myDT.Rows.Add(new object[] {"00","01" });
                //myDT.Rows.Add(new object[] { "10", "11" });

                Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table(layoutTab.Rows[0].Cells[0]);
                tab1.ColumnWidths = "50% 50%";
                //tab1.ColumnAdjustment = ColumnAdjustmentType.AutoFitToContent;

                tab1.Rows.Add().Cells.Add().Paragraphs.Add(new Aspose.Pdf.Text("hello world"));

                Aspose.Pdf.Table tab2 = new Aspose.Pdf.Table(tab1.Rows.Add().Cells.Add());
                tab2.DefaultCellBorder = new BorderInfo((int)BorderSide.All);
                tab1.DefaultCellBorder = new BorderInfo((int)BorderSide.All);
                tab2.ColumnWidths = "50% 50%";
                tab2.ImportDataTable(myDT, true, 0, 0);
                tab1.Rows[1].Cells[0].Paragraphs.Add(tab2);

                layoutTab.Rows[0].Cells[0].Paragraphs.Add(tab1);
                sec1.Paragraphs.Add(layoutTab);

                pdf1.Save("D:/nested.pdf");

    Thanks.

     
  •  08-24-2007, 2:32 AM 92129 in reply to 92033

    Re: PDF: Nested tables and columnSpan

    Attachment: Present (inaccessible)
    Thanks for a quick reply!

    But unfortunately this doesn't work when the data (or columnname) in
        DataColumn dc = new DataColumn("Col1");
    is longer, for ex:
       
    DataColumn dc = new DataColumn("Col1xxxxxxxxxxxxxxxxxxxxxx");
    See the attatched pdf.

    I've also tried this:
        tab1.ColumnWidths = "100% 100%";
        tab1.ColumnAdjustment = ColumnAdjustmentType.AutoFitToContent;
    Then the columns become a bit wider but the nested table still only fit to the first cell.

    Thanks,
    Sara
     
  •  08-24-2007, 9:15 AM 92163 in reply to 92129

    Re: PDF: Nested tables and columnSpan

    Attachment: Present (inaccessible)

    Hi,

    I have changed the code to some extent and I think I am able to produce the result you want. Kindly check it if this fit to you requirement.If not, then can you please send me a sample Pdf/Image so that I can help you more.

    [C#]

    Aspose.Pdf.Pdf pdf1 = new Aspose.Pdf.Pdf();

    Aspose.Pdf.Section sec1 = pdf1.Sections.Add();

    Aspose.Pdf.Table layoutTab = new Aspose.Pdf.Table(sec1);

    layoutTab.DefaultCellBorder = new BorderInfo((int)BorderSide.All);

    layoutTab.ColumnWidths = "50% 50%";

    layoutTab.ColumnAdjustment = ColumnAdjustmentType.Customized;

    layoutTab.Rows.Add().Cells.Add();

    layoutTab.Rows[0].Cells[0].ColumnsSpan = 2;

    DataTable myDT = new DataTable();

    DataColumn dc = new DataColumn("Col1xxxxxxxxxxxxxxxxxxxxxxxxxxxxx");

    DataColumn dc1 = new DataColumn("Col2");

    myDT.Columns.Add(dc);

    myDT.Columns.Add(dc1);

    myDT.Rows.Add(new object[] { "00", "01" });

    //myDT.Rows.Add(new object[] { "10", "11" });

     

    Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table(layoutTab.Rows[0].Cells[0]);

    tab1.ColumnWidths = "50% 50%";

    tab1.ColumnAdjustment = ColumnAdjustmentType.AutoFitToContent;

    tab1.Rows.Add().Cells.Add().Paragraphs.Add(new Aspose.Pdf.Text("hello world"));

    Aspose.Pdf.Table tab2 = new Aspose.Pdf.Table(tab1.Rows.Add().Cells.Add());

    tab2.DefaultCellBorder = new BorderInfo((int)BorderSide.All);

    tab1.DefaultCellBorder = new BorderInfo((int)BorderSide.All);

    tab2.ColumnWidths = "50% 50%";

    tab2.ColumnAdjustment = ColumnAdjustmentType.AutoFitToContent;

    tab2.ImportDataTable(myDT, true, 0, 0);

    tab1.Rows[0].Cells[0].ColumnsSpan = 2;

    tab1.Rows[1].Cells[0].ColumnsSpan = 2;

    tab1.Rows[1].Cells[0].Paragraphs.Add(tab2);

    layoutTab.Rows[0].Cells[0].Paragraphs.Add(tab1);

    sec1.Paragraphs.Add(layoutTab);

    pdf1.Save("D:/nested.pdf");

    Thanks.

     
  •  08-24-2007, 10:37 AM 92178 in reply to 92163

    Re: PDF: Nested tables and columnSpan

    Attachment: Present (inaccessible)
    Hi
    Sorry.. the problem remains.
    I've tried to draw a picture in PowerPoint to show what I want it to look like (first slide) and what the problem with the code is (second slide). I added a column in myDT to make it easier to visualize the problem. Please let me know if it still is unclear.

    The text-object has no problem spanning over two columns, but the nested Table seems to have that problem. When I create a Table-object I have to tell in which cell to put it (new Table(Cell)), but I can't do that with the Text-object (new Text()). Do you think that could cause this problem?

    //Sara
     
  •  08-24-2007, 10:00 PM 92251 in reply to 92178

    Re: PDF: Nested tables and columnSpan

    I found the column width setting with % does not work for nested table with ColumnSpan. I have logged this issue as PDFNET-3652. As a workaround you can set the column width with points value instead of %.

    Tommy Wang
    Lead Developer
    Aspose Changsha Team
    About Us
    Contact Us
     
  •  09-16-2007, 6:11 PM 95057 in reply to 92178

    Re: PDF: Nested tables and columnSpan

    Attachment: Present (inaccessible)
    Hi,

    The feature is supported now. Please try the attachment before we publish new hotfix.

    Best regards.

    Hans Zhang
    Product Developer
    Aspose Changsha Team
    About Us
    Contact Us
     
View as RSS news feed in XML