當前位置: 首頁>>代碼示例>>C#>>正文


C# Table.InsertTableAfterSelf方法代碼示例

本文整理匯總了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;
        }
開發者ID:pucit,項目名稱:SchoolAutomationSource,代碼行數:55,代碼來源:print.cs

示例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;
        }
開發者ID:holgersson1988,項目名稱:TobiiThesis,代碼行數:74,代碼來源:Program.cs


注:本文中的Novacode.Table.InsertTableAfterSelf方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。