彩票走势图

Aspose.Pdf使用小结-如何根据表单行中的单元格数量动态设置列宽

原创|其它|编辑:郝浩|2011-08-05 10:46:17.000|阅读 1392 次

概述:Aspose.Pdf for .NET可创建表单对象并且将表单对象置于PDF文档中。添加表单对象前,我们需要指定列宽信息,单元格中也被加入指定信息。但是, 我们可以在运行时指定列宽信息。当表的宽高比例为100%时,列宽的调整便基于一行中单元格的数量。请大家看看下面的一段代码,在下面的代码示例中,我们已经在Section宽度的基础上调整了单元格的宽度:

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

  Aspose.Pdf for .NET可创建表单对象并且将表单对象置于PDF文档中。添加表单对象前,我们需要指定列宽信息,单元格中也被加入指定信息。但是, 我们可以在运行时指定列宽信息。当表的宽高比例为100%时,列宽的调整便基于一行中单元格的数量。

  请大家看看下面的一段代码,在下面的代码示例中,我们已经在Section宽度的基础上调整了单元格的宽度:

[C#]

// create Pdf Instance

Pdf pdf = new Pdf();

        // create section object and add it to pdf object

        Section sec1 = pdf.Sections.Add();

        // create a table instance

        Table mytable = new Table();

        // specify the default border for table object and set its color as Navy

   ;     mytable.DefaultCellBorder = new BorderInfo((int)BorderSide.All, 1f, new Aspose.Pdf.Color("Navy"));

        // specify the border information for table object

        mytable.Border= new BorderInfo((int)BorderSide.All, 1f, new Aspose.Pdf.Color("Navy"));

        // define initial width information for table cells

        mytable.ColumnWidths = "100 100";

        // create a row object and add it to table

        Row row1 = mytable.Rows.Add();

        // create loop to add specify the number of columns to be added to table row

        for (int Column_Counter = 1; Column_Counter <=7; Column_Counter++)

        {

    // create a cell object and add it to table row

    Cell Cell = row1.Cells.Add("Cell (1,"+ Column_Counter.ToString() +")");

        }

      ;  // define the variable to keep record of number of columns in table

        int TableColumn = 0;

        // traverse through each table cell in row object

   &nbsp; &nbsp;  foreach (Cell InnerCell in row1.Cells)

        {

     ;   // specify the width information for each column based on section objects margin and width values

      ;  // set the width value as, get the total width of section and subtract left and right margin and divide

&nbsp;       // it with total number of cells in a particular table row

   &nbsp;    mytable.SetColumnWidth(TableColumn, (sec1.PageInfo.PageWidth - sec1.PageInfo.Margin.Left - sec1.PageInfo.Margin.Right)/ row1.Cells.Count);

   &nbsp;    // increase the value of variable holding the column count information

    &nbsp;   TableColumn += 1;

        }

// add table to paragraphs collection of section

        sec1.Paragraphs.Add(mytable);

 &nbsp;      // save the resultant PDF document

        pdf.Save("d:/pdftest/DynamicTableWidth.pdf");

[VB.NET]

' create Pdf Instance

      &nbsp; Dim pdf As Pdf = New Pdf()

 &nbsp;      ' create section object and add it to pdf object

        Dim sec1 As Aspose.Pdf.Section = pdf.Sections.Add()

        ' create a table instance

        Dim mytable As Table = New Table()

        ' specify the default border for table object and set its color as Navy

 ;       mytable.DefaultCellBorder = New BorderInfo(BorderSide.All, 1.0F, New Aspose.Pdf.Color("Navy"))

        ' specify the border information for table object

        mytable.Border = New BorderInfo(BorderSide.All, 1.0F, New Aspose.Pdf.Color("Navy"))

    &nbsp;   ' define initial width information for table cells

    ;   ; mytable.ColumnWidths = "100 100"

      &nbsp; ' create a row object and add it to table

   &nbsp;    Dim row1 As Row = mytable.Rows.Add()

        ' create loop to add specify the number of columns to be added to table row

       ; For Column_Counter As Integer = 1 To 5 Step 1

         &nbsp;  ' create a cell object and add it to table row

            Dim Cell As Cell = row1.Cells.Add("Cell (1," + Column_Counter.ToString() + ")")

        Next

        ' define the  variable to keep record of number of columns in table

        Dim TableColumn As Integer = 0

  ;      ' create a cell object

        Dim InnerCell As Cell

        ' traverse through each table cell in row object

        For Each InnerCell In row1.Cells

            ' specify the width information for each column based on section objects margin and width values

&nbsp;           ' set the width value as, get the total width of section and subtract left and right margin and divide

            ' it with total number of cells in a particular table row

            mytable.SetColumnWidth(TableColumn, (sec1.PageInfo.PageWidth - sec1.PageInfo.Margin.Left - sec1.PageInfo.Margin.Right) / row1.Cells.Count)

            ' increase the value of variable holding the column count information

      &nbsp; &nbsp;   TableColumn += 1

        Next

        ' add table to paragraphs collection of section

    &nbsp;   sec1.Paragraphs.Add(mytable)

      &nbsp; ' save the resultant PDF document

        pdf.Save("d:/pdftest/DynamicTableWidth.pdf&quot;)


(慧都控件网版权所有,转载请注明出处,否则追究法律责任)
标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@capbkgr.cn

文章转载自:慧都控件网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP