Exemplo n.º 1
0
        private static DocX CreateInvoiceFromTemplate(DocX templateDoc)
        {
            // Fill in the document custom properties.
            templateDoc.AddCustomProperty(new CustomProperty("InvoiceNumber", 1355));
            templateDoc.AddCustomProperty(new CustomProperty("InvoiceDate", new DateTime(2016, 10, 15).ToShortDateString()));
            templateDoc.AddCustomProperty(new CustomProperty("CompanyName", "Toms Telecoms"));
            templateDoc.AddCustomProperty(new CustomProperty("CompanySlogan", "Always with you"));
            templateDoc.AddCustomProperty(new CustomProperty("ClientName", "James Doh"));
            templateDoc.AddCustomProperty(new CustomProperty("ClientStreetName", "123 Main street"));
            templateDoc.AddCustomProperty(new CustomProperty("ClientCity", "Springfield, Ohio"));
            templateDoc.AddCustomProperty(new CustomProperty("ClientZipCode", "54789"));
            templateDoc.AddCustomProperty(new CustomProperty("ClientPhone", "438-585-9636"));
            templateDoc.AddCustomProperty(new CustomProperty("ClientMail", "*****@*****.**"));
            templateDoc.AddCustomProperty(new CustomProperty("CompanyStreetName", "1458 Thompson Road"));
            templateDoc.AddCustomProperty(new CustomProperty("CompanyCity", "Los Angeles, California"));
            templateDoc.AddCustomProperty(new CustomProperty("CompanyZipCode", "90210"));
            templateDoc.AddCustomProperty(new CustomProperty("CompanyPhone", "1-965-434-5786"));
            templateDoc.AddCustomProperty(new CustomProperty("CompanySupport", "*****@*****.**"));

            // Remove the default logo and add the new one.
            var paragraphWithDefaultLogo = MiscellaneousSample.GetParagraphContainingPicture(templateDoc);

            if (paragraphWithDefaultLogo != null)
            {
                paragraphWithDefaultLogo.Pictures.First().Remove();
                var newLogo = templateDoc.AddImage(MiscellaneousSample.MiscellaneousSampleResourcesDirectory + @"Phone.png");
                paragraphWithDefaultLogo.AppendPicture(newLogo.CreatePicture(60, 180));
            }

            // Fill the details table.
            MiscellaneousSample.FillDetailsTable(ref templateDoc);

            return(templateDoc);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load a document containing a templated invoice with Custom properties, tables, paragraphs and a picture.
        /// Set the values of those Custom properties, modify the picture, and fill the details table.
        /// </summary>
        public static void CreateInvoice()
        {
            Console.WriteLine("\tCreateInvoice()");

            // Load the templated invoice.
            var templateDoc = DocX.Load(MiscellaneousSample.MiscellaneousSampleResourcesDirectory + @"TemplateInvoice.docx") as DocX;

            if (templateDoc != null)
            {
                // Create the invoice from the templated invoice.
                var invoice = MiscellaneousSample.CreateInvoiceFromTemplate(templateDoc);

                invoice.SaveAs(MiscellaneousSample.MiscellaneousSampleOutputDirectory + @"CreateInvoice.docx");
                Console.WriteLine("\tCreated: CreateInvoice.docx\n");
            }
        }
Exemplo n.º 3
0
        private static void FillDetailsTable(ref DocX templateDoc)
        {
            // The datas that will fill the details table.
            var datas = MiscellaneousSample.GetDetailsData();

            // The table from the templated invoice.
            var detailsTable = templateDoc.Tables.LastOrDefault();

            if (detailsTable == null)
            {
                return;
            }

            // Remove all rows of the details table, except the header one.
            while (detailsTable.Rows.Count > 1)
            {
                detailsTable.RemoveRow();
            }

            // Loop through each data rows and use them to add new rows in the detailsTable.
            foreach (DataRow data in datas.Rows)
            {
                var newRow = detailsTable.InsertRow();
                newRow.Cells.First().InsertParagraph(data.ItemArray.First().ToString());
                newRow.Cells.Last().InsertParagraph(data.ItemArray.Last().ToString());
            }

            // Calculate the total amount.
            var amountStrings = detailsTable.Rows.Select(r => r.Cells.Last().Paragraphs.Last().Text.Remove(0, 1)).ToList();

            amountStrings.RemoveAt(0); // remove the header
            var totalAmount = amountStrings.Select(s => double.Parse(s)).Sum();

            // Add a Total row in the details table.
            var totalRow = detailsTable.InsertRow();

            totalRow.Cells.First().InsertParagraph("TOTAL:");
            totalRow.Cells.Last().InsertParagraph(string.Format("${0}", totalAmount));
        }
Exemplo n.º 4
0
        private 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.AddAppProperties();
            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();
        }
Exemplo n.º 5
0
        private static void Main(string[] args)
        {
            var version       = Assembly.GetExecutingAssembly().GetName().Version;
            var versionNumber = version.Major + "." + version.Minor;

            Console.WriteLine("\nRunning Examples of Xceed Words for .NET version " + versionNumber + ".\n");

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

            //Document
            DocumentSample.AddCustomProperties();
            DocumentSample.ReplaceTextWithText();
            DocumentSample.ReplaceTextWithObjects();
            DocumentSample.ApplyTemplate();
            DocumentSample.AppendDocument();
            DocumentSample.LoadDocumentWithFilename();
            DocumentSample.LoadDocumentWithStream();
            DocumentSample.LoadDocumentWithStringUrl();
            DocumentSample.AddHtmlFromFile();
            DocumentSample.AddRtfFromFile();

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

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

            //Header/Footers
            HeaderFooterSample.HeadersFooters();

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

            //Hyperlink
            HyperlinkSample.Hyperlinks();

            //Section
            SectionSample.InsertSections();
            SectionSample.SetPageOrientations();

            //Lists
            ListSample.AddList();
            ListSample.CloneLists();

            //Equations
            EquationSample.InsertEquation();

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

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

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

            //Lines
            LineSample.InsertHorizontalLine();

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

            //Parallel
            ParallelSample.DoParallelActions();

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

            //PDF
            PdfSample.ConvertToPDF();

            //Shape
            ShapeSample.AddShape();
            ShapeSample.AddShapeWithTextWrapping();
            ShapeSample.AddTextBox();
            ShapeSample.AddTextBoxWithTextWrapping();

            //CheckBox
            CheckBoxSample.ModifyCheckBox();
            CheckBoxSample.AddCheckBox();

            Console.WriteLine("\nDone running Examples of Xceed Words for .NET version " + versionNumber + ".\n");
            Console.WriteLine("\nPress any key to exit.");
            Console.ReadKey();
        }