原創|其它|編輯:郝浩|2011-08-05 10:46:17.000|閱讀 1414 次
概述: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
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
// 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
TableColumn += 1;
}
// add table to paragraphs collection of section
sec1.Paragraphs.Add(mytable);
// save the resultant PDF document
pdf.Save("d:/pdftest/DynamicTableWidth.pdf");
[VB.NET]
' create Pdf Instance
Dim pdf As Pdf = New Pdf()
' 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"))
' define initial width information for table cells
mytable.ColumnWidths = "100 100"
' create a row object and add it to table
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
' 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
' 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
TableColumn += 1
Next
' add table to paragraphs collection of section
sec1.Paragraphs.Add(mytable)
' save the resultant PDF document
pdf.Save("d:/pdftest/DynamicTableWidth.pdf")
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網