本文整理汇总了C#中Novacode.Table.InsertTableAfterSelf方法的典型用法代码示例。如果您正苦于以下问题:C# Table.InsertTableAfterSelf方法的具体用法?C# Table.InsertTableAfterSelf怎么用?C# Table.InsertTableAfterSelf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Novacode.Table
的用法示例。
在下文中一共展示了Table.InsertTableAfterSelf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAndInsertInvoiceTableAfter
private static Table CreateAndInsertInvoiceTableAfter(Table t, ref DocX document)
{
// Grab data from somewhere (Most likely a database)
schooldbEntities DAO = new schooldbEntities();
List<teacher> tlist = (from tt in DAO.teachers select tt).ToList<teacher>();
/*
* The trick to replacing one Table with another,
* is to insert the new Table after the old one,
* and then remove the old one.
*/
Table invoice_table = t.InsertTableAfterSelf(tlist.Count + 1, 4);
invoice_table.Design = TableDesign.LightShadingAccent1;
#region Table title
Formatting table_title = new Formatting();
table_title.Bold = true;
invoice_table.Rows[0].Cells[0].Paragraph.InsertText("Serial No.", false, table_title);
invoice_table.Rows[0].Cells[0].Paragraph.Alignment = Alignment.center;
invoice_table.Rows[0].Cells[1].Paragraph.InsertText("Employee Name", false, table_title);
invoice_table.Rows[0].Cells[1].Paragraph.Alignment = Alignment.center;
invoice_table.Rows[0].Cells[2].Paragraph.InsertText("Account No.", false, table_title);
invoice_table.Rows[0].Cells[2].Paragraph.Alignment = Alignment.center;
invoice_table.Rows[0].Cells[3].Paragraph.InsertText("Salary", false, table_title);
invoice_table.Rows[0].Cells[3].Paragraph.Alignment = Alignment.center;
#endregion
// Loop through the rows in the Table and insert data from the data source.
for (int row = 1; row < tlist.Count; row++)
{
Paragraph cell_paragraph = invoice_table.Rows[row].Cells[0].Paragraph;
cell_paragraph.InsertText(row.ToString(), false);
cell_paragraph = invoice_table.Rows[row].Cells[1].Paragraph;
cell_paragraph.InsertText(tlist[row - 1].TeacherName.ToString(), false);
cell_paragraph = invoice_table.Rows[row].Cells[2].Paragraph;
cell_paragraph.InsertText(tlist[row - 1].Account_Number.ToString(), false);
cell_paragraph = invoice_table.Rows[row].Cells[3].Paragraph;
cell_paragraph.InsertText(tlist[row - 1].BasicSalary.ToString(), false);
}
// Let the tables coloumns expand to fit its contents.
invoice_table.AutoFit = AutoFit.Contents;
// Center the Table
invoice_table.Alignment = Alignment.center;
// Return the invloce table now that it has been created.
return invoice_table;
}
示例2: CreateAndInsertInvoiceTableAfter
private static Table CreateAndInsertInvoiceTableAfter(Table t, ref DocX document)
{
// Grab data from somewhere (Most likely a database)
DataTable data = GetDataFromDatabase();
/*
* The trick to replacing one Table with another,
* is to insert the new Table after the old one,
* and then remove the old one.
*/
Table invoice_table = t.InsertTableAfterSelf(data.Rows.Count + 1, data.Columns.Count);
invoice_table.Design = TableDesign.LightShadingAccent1;
#region Table title
Formatting table_title = new Formatting();
table_title.Bold = true;
invoice_table.Rows[0].Cells[0].Paragraphs[0].InsertText("Description", false, table_title);
invoice_table.Rows[0].Cells[0].Paragraphs[0].Alignment = Alignment.center;
invoice_table.Rows[0].Cells[1].Paragraphs[0].InsertText("Hours", false, table_title);
invoice_table.Rows[0].Cells[1].Paragraphs[0].Alignment = Alignment.center;
invoice_table.Rows[0].Cells[2].Paragraphs[0].InsertText("Rate", false, table_title);
invoice_table.Rows[0].Cells[2].Paragraphs[0].Alignment = Alignment.center;
invoice_table.Rows[0].Cells[3].Paragraphs[0].InsertText("Amount", false, table_title);
invoice_table.Rows[0].Cells[3].Paragraphs[0].Alignment = Alignment.center;
#endregion
// Loop through the rows in the Table and insert data from the data source.
for (int row = 1; row < invoice_table.RowCount; row++)
{
for (int cell = 0; cell < invoice_table.Rows[row].Cells.Count; cell++)
{
Paragraph cell_paragraph = invoice_table.Rows[row].Cells[cell].Paragraphs[0];
cell_paragraph.InsertText(data.Rows[row - 1].ItemArray[cell].ToString(), false);
}
}
// We want to fill in the total by suming the values from the amount column.
Row total = invoice_table.InsertRow();
total.Cells[0].Paragraphs[0].InsertText("Total:", false);
Paragraph total_paragraph = total.Cells[invoice_table.ColumnCount - 1].Paragraphs[0];
/*
* Lots of people are scared of LINQ,
* so I will walk you through this line by line.
*
* invoice_table.Rows is an IEnumerable<Row> (i.e a collection of rows), with LINQ you can query collections.
* .Where(condition) is a filter that you want to apply to the items of this collection.
* My condition is that the index of the row must be greater than 0 and less than RowCount.
* .Select(something) lets you select something from each item in the filtered collection.
* I am selecting the Text value from each row, for example €100, then I am remove the €,
* and then I am parsing the remaining string as a double. This will return a collection of doubles,
* the final thing I do is call .Sum() on this collection which return one double the sum of all the doubles,
* this is the total.
*/
double totalCost =
(
invoice_table.Rows
.Where((row, index) => index > 0 && index < invoice_table.RowCount - 1)
.Select(row => double.Parse(row.Cells[row.Cells.Count() - 1].Paragraphs[0].Text.Remove(0, 1)))
).Sum();
// Insert the total calculated above using LINQ into the total Paragraph.
total_paragraph.InsertText(string.Format("€{0}", totalCost), false);
// Let the tables columns expand to fit its contents.
invoice_table.AutoFit = AutoFit.Contents;
// Center the Table
invoice_table.Alignment = Alignment.center;
// Return the invloce table now that it has been created.
return invoice_table;
}