コード例 #1
0
        /// <summary>
        /// Load a document, gets its table and replace the default row with updated copies of it.
        /// </summary>
        public static void CreateRowsFromTemplate()
        {
            Console.WriteLine("\tCreateRowsFromTemplate()");

            // Load a document
            using (DocX document = DocX.Load(TableSample.TableSampleResourcesDirectory + @"DocumentWithTemplateTable.docx"))
            {
                // get the table with caption "GROCERY_LIST" from the document.
                var groceryListTable = document.Tables.FirstOrDefault(t => t.TableCaption == "GROCERY_LIST");
                if (groceryListTable == null)
                {
                    Console.WriteLine("\tError, couldn't find table with caption GROCERY_LIST in current document.");
                }
                else
                {
                    if (groceryListTable.RowCount > 1)
                    {
                        // Get the row pattern of the second row.
                        var rowPattern = groceryListTable.Rows[1];

                        // Add items (rows) to the grocery list.
                        TableSample.AddItemToTable(groceryListTable, rowPattern, "Banana");
                        TableSample.AddItemToTable(groceryListTable, rowPattern, "Strawberry");
                        TableSample.AddItemToTable(groceryListTable, rowPattern, "Chicken");
                        TableSample.AddItemToTable(groceryListTable, rowPattern, "Bread");
                        TableSample.AddItemToTable(groceryListTable, rowPattern, "Eggs");
                        TableSample.AddItemToTable(groceryListTable, rowPattern, "Salad");

                        // Remove the pattern row.
                        rowPattern.Remove();
                    }
                }

                document.SaveAs(TableSample.TableSampleOutputDirectory + @"CreateTableFromTemplate.docx");
                Console.WriteLine("\tCreated: CreateTableFromTemplate.docx\n");
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

            //Paragraphs
            ParagraphSample.SimpleFormattedParagraphs();
            ParagraphSample.ForceParagraphOnSinglePage();
            ParagraphSample.ForceMultiParagraphsOnSinglePage();
            ParagraphSample.TextActions();
            ParagraphSample.Heading();

            //Document
            DocumentSample.AddCustomProperties();
            DocumentSample.ReplaceText();
            DocumentSample.ApplyTemplate();
            DocumentSample.AppendDocument();

            //Images
            ImageSample.AddPicture();
            ImageSample.CopyPicture();

            ImageSample.ModifyImage();

            //Indentation/Direction/Margins
            MarginSample.SetDirection();
            MarginSample.Indentation();
            MarginSample.Margins();

            //Header/Footers
            HeaderFooterSample.HeadersFooters();

            //Tables
            TableSample.InsertRowAndImageTable();
            TableSample.TextDirectionTable();
            TableSample.CreateRowsFromTemplate();
            TableSample.ColumnsWidth();
            TableSample.MergeCells();

            //Hyperlink
            HyperlinkSample.Hyperlinks();

            //Section
            SectionSample.InsertSections();

            //Lists
            ListSample.AddList();

            //Equations
            EquationSample.InsertEquation();

            //Bookmarks
            BookmarkSample.InsertBookmarks();
            BookmarkSample.ReplaceText();

            //Charts
            ChartSample.BarChart();
            ChartSample.LineChart();
            ChartSample.PieChart();
            ChartSample.Chart3D();

            //Tale of Content
            TableOfContentSample.InsertTableOfContent();
            TableOfContentSample.InsertTableOfContentWithReference();

            //Lines
            LineSample.InsertHorizontalLine();

            //Protection
            ProtectionSample.AddPasswordProtection();
            ProtectionSample.AddProtection();

            //Parallel
            ParallelSample.DoParallelActions();

            //Others
            MiscellaneousSample.CreateRecipe();
            MiscellaneousSample.CompanyReport();
            MiscellaneousSample.CreateInvoice();

            Console.WriteLine("\nPress any key to exit.");
            Console.ReadKey();

            Console.ReadLine();
        }