Exemplo n.º 1
0
        public static void AddInlineImage()
        {
            WordDocument        document = new WordDocument();
            WordDocumentBuilder builder  = new WordDocumentBuilder(document);

            //Add in-line image using builder
            builder.InsertText("Simple sentence 1 in line. ");
            using (Stream stream = File.OpenRead("sample.jpg"))
            {
                builder.InsertImageInline(stream, "jpg");
            }
            builder.InsertText("Simple sentence 2 in line");

            //Add in-line image using Paragraph object
            Paragraph paragraph = builder.InsertParagraph();
            //Add text before
            TextInline textStart = paragraph.Inlines.AddText();

            textStart.Text = "Text add using paragraph start.";
            //Insert image in the middle of text content
            ImageInline imageInline = paragraph.Inlines.AddImageInline();

            using (Stream stream = File.OpenRead("sample.png"))
            {
                imageInline.Image.ImageSource = new Basic.Media.ImageSource(stream, "png");
            }
            //Add text after
            TextInline textEnd = paragraph.Inlines.AddText();

            textEnd.Text = "Text add using paragraph end.";

            WordFile wordFile = new WordFile();

            File.WriteAllBytes("AddImageInline.docx", wordFile.Export(document));
        }
Exemplo n.º 2
0
        public static void AddTableFrame()
        {
            WordDocument        document = new WordDocument();
            WordDocumentBuilder builder  = new WordDocumentBuilder(document);

            builder.TableState.Indent         = 100;
            builder.TableState.PreferredWidth = new TableWidthUnit(300);
            builder.TableState.LayoutType     = TableLayoutType.FixedWidth;

            Paragraph tableTitle = builder.InsertParagraph();

            tableTitle.TextAlignment = Alignment.Center;
            builder.InsertLine("Table Frame");

            Table table = builder.InsertTable();

            table = CreateTableFrame(table);

            WordFile wordFile = new WordFile();

            using (var stream = File.OpenWrite("AddTableFrame.docx"))
            {
                wordFile.Export(document, stream);
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("command <Markdown File Path> <Base docx Path>");
                return;
            }

            var markdownFilePath = args[0];
            var docxFilePath     = args[1];

            // Create a output file by copying of base docx file.
            var outputFilePath = Path.GetDirectoryName(markdownFilePath) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(markdownFilePath) + ".docx";

            using (var builder = new WordDocumentBuilder(docxFilePath, outputFilePath))
            {
                builder.AddHeader("Header 1", "Heading1");

                builder.AddParagraph(@"これはサンプル テキストです。これはサンプル テキストです。これはサンプル テキストです。これはサンプル テキストです。これはサンプル テキストです。これはサンプル テキストです。");

                builder.AddListItem("List Item 1", "ListParagraph");

                var imageFilePath = @"D:\Temp\md2docx\image1.png";
                builder.AddImage(imageFilePath, "Figure");


                builder.Save();
            }
        }
Exemplo n.º 4
0
        public static void AddImageWatermark()
        {
            WordFile            wordFile = new WordFile();
            WordDocument        document = wordFile.Import(File.ReadAllBytes("Sample.docx"));
            WordDocumentBuilder builder  = new WordDocumentBuilder(document);

            //Customize the setting of image watermark
            ImageWatermarkSettings setting = new ImageWatermarkSettings();

            setting.Width    = 100;
            setting.Height   = 50;
            setting.Rotation = -45;
            using (Stream stream = File.OpenRead("watermark.png"))
            {
                setting.ImageSource = new Basic.Media.ImageSource(stream, "png");
            }

            //Create watermark with settings
            Watermark imageWatermark = new Watermark(setting);

            //Add watermark to Header object
            builder.SetWatermark(imageWatermark, document.Sections[0].Headers.Add());
            //builder.SetWatermark(imageWatermark, document.Sections[0], HeaderFooterType.Default);

            File.WriteAllBytes("AddImageWatermark.docx", wordFile.Export(document));
        }
Exemplo n.º 5
0
        private void StampaRadnogNaloga()
        {
            //  //string dir = Environment.SpecialFolder.MyDocuments + "\\ServisDB\\";

            string dir = System.IO.Path.Combine(Environment.GetFolderPath(
                                                    Environment.SpecialFolder.MyDoc‌​uments), "ServisDB");

            if (Directory.Exists(dir) == false)
            {
                Directory.CreateDirectory(dir);
            }
            object   o          = dgvPrijave.SelectedRows[0].DataBoundItem;
            string   brojnaloga = ((DataRowView)o).Row.ItemArray[1].ToString();
            string   kupac      = ((DataRowView)o).Row.ItemArray[4].ToString();
            string   adresa     = ((DataRowView)o).Row.ItemArray[5].ToString();
            string   telefon    = ((DataRowView)o).Row.ItemArray[6].ToString();
            string   predmet    = ((DataRowView)o).Row.ItemArray[11].ToString();
            DateTime datum      = (DateTime)((DataRowView)o).Row.ItemArray[2];

            string serviser = ((DataRowView)o).Row.ItemArray[13].ToString();

            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict.Add("BROJNALOGA", brojnaloga);
            dict.Add("PREDMET", predmet);
            dict.Add("KUPAC", kupac + ", " + telefon + ", " + adresa);
            dict.Add("SERVISER", serviser);
            dict.Add("DATUM", datum.ToString("dd.MM.yyyy"));
            dict.Add("DATUMNALOGA", datum.ToString("dd.MM.yyyy"));

            string fileName = dir + "\\" + brojnaloga.Replace("/", "-") + ".docx";

            WordDocumentBuilder.FillBookmarksUsingOpenXml("RadniNalog.docx", fileName, dict);
            Process.Start(fileName);
        }
Exemplo n.º 6
0
        public static void AddBookmark()
        {
            WordDocument        document = new WordDocument();
            WordDocumentBuilder builder  = new WordDocumentBuilder(document);

            builder.InsertLine("First paragraph in this document.");

            //Insert some content before bookmark
            builder.InsertText("Second paragraph start. ");
            //Select the content you want to bookmark
            TextInline textBookmark = builder.InsertText("This is bookmark. ");

            //Insert some content after bookmark
            builder.InsertText("Second paragraph end.");

            //Add bookmark with selected content
            builder.InsertBookmark("bookmark1", textBookmark, textBookmark);

            WordFile wordFile = new WordFile();

            using (var stream = File.OpenWrite("AddBookmark.docx"))
            {
                wordFile.Export(document, stream);
            }
        }
Exemplo n.º 7
0
        public static void AddComment()
        {
            WordDocument        document = new WordDocument();
            WordDocumentBuilder builder  = new WordDocumentBuilder(document);

            builder.InsertLine("First paragraph in this document.");

            //Insert some content before comment
            builder.InsertText("Second paragraph start. ");
            //Select the content you want to comment
            TextInline textComment = builder.InsertText("Text has comment. ");

            //Insert some content after comment
            builder.InsertText("Second paragraph end.");

            //Add comment with selected content
            Comment comment = builder.InsertComment("Comment details here", textComment, textComment);

            comment.Author = "iDiTect";
            comment.Date   = DateTime.Now;

            WordFile wordFile = new WordFile();

            using (var stream = File.OpenWrite("AddComment.docx"))
            {
                wordFile.Export(document, stream);
            }
        }
Exemplo n.º 8
0
        public static void ProtectDocument()
        {
            //Load an existing word file
            WordFile            wordFile = new WordFile();
            WordDocument        document = wordFile.Import(File.ReadAllBytes("Sample.docx"));
            WordDocumentBuilder builder  = new WordDocumentBuilder(document);

            //Protect file with password and permission
            builder.Protect("password", Protection.ProtectionMode.AllowComments);

            File.WriteAllBytes("Protected.docx", wordFile.Export(document));
        }
Exemplo n.º 9
0
        public static void ReplaceText()
        {
            WordFile     wordFile = new WordFile();
            WordDocument document = wordFile.Import(File.ReadAllBytes("Sample.docx"));

            WordDocumentBuilder builder = new WordDocumentBuilder(document);

            //Replace target text in whole document, match-case and match-whole-word are supported
            builder.ReplaceText("Page", "as", true, true);

            File.WriteAllBytes("ReplaceText.docx", wordFile.Export(document));
        }
Exemplo n.º 10
0
        private void Stampa()
        {
            //  //string dir = Environment.SpecialFolder.MyDocuments + "\\ServisDB\\";

            string dir = System.IO.Path.Combine(Environment.GetFolderPath(
                                                    Environment.SpecialFolder.MyDoc‌​uments), "ServisDB");

            if (Directory.Exists(dir) == false)
            {
                Directory.CreateDirectory(dir);
            }
            object   o         = dgvPrijave.SelectedRows[0].DataBoundItem;
            string   rednibroj = ((DataRowView)o).Row.ItemArray[0].ToString();
            string   kupac     = ((DataRowView)o).Row.ItemArray[5].ToString();
            string   adresa    = ((DataRowView)o).Row.ItemArray[6].ToString();
            string   lk        = ((DataRowView)o).Row.ItemArray[4].ToString();
            string   jmbg      = ((DataRowView)o).Row.ItemArray[3].ToString();
            decimal  uplaceno  = (decimal)((DataRowView)o).Row.ItemArray[10];
            string   brojrata  = ((DataRowView)o).Row.ItemArray[14].ToString();
            DateTime datum     = (DateTime)((DataRowView)o).Row.ItemArray[1];
            decimal  iznos     = (decimal)((DataRowView)o).Row.ItemArray[13];
            string   napomena  = ((DataRowView)o).Row.ItemArray[18].ToString();

            List <UgovorRata> rate = PersistanceManager.ReadUgovorRata(rednibroj);
            string            plan = "";

            for (int i = 0; i < rate.Count; i++)
            {
                plan = plan + Environment.NewLine + (i + 1).ToString() + ". do " + rate[i].RokPlacanja.ToString("dd.MM.yyyy") + " - iznos: " + rate[i].Iznos.ToString("N2") + " KM";
            }


            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict.Add("OTPLATNIPLAN", plan);
            dict.Add("KUPAC", kupac);
            dict.Add("ADRESA", adresa);
            dict.Add("LK", lk);
            dict.Add("JMBG", jmbg);
            dict.Add("UPLACENO", uplaceno.ToString("N2"));
            dict.Add("BROJRATA", brojrata.ToString());
            dict.Add("DATUM", datum.ToString("dd.MM.yyyy"));
            dict.Add("IZNOSRATE", (Math.Round((iznos - uplaceno) / int.Parse(brojrata), 2, MidpointRounding.AwayFromZero)).ToString("N2"));
            dict.Add("UKUPANIZNOS", (iznos).ToString("N2"));
            dict.Add("PREDMET", napomena);
            string fileName = dir + "\\" + rednibroj.Replace("/", "-") + ".docx";

            WordDocumentBuilder.FillBookmarksUsingOpenXml("Ugovor.docx", fileName, dict);
            Process.Start(fileName);
        }
Exemplo n.º 11
0
        public static void UnprotectDocument()
        {
            //Load the protected word file
            WordFile            wordFile = new WordFile();
            WordDocument        document = wordFile.Import(File.ReadAllBytes("Protected.docx"));
            WordDocumentBuilder builder  = new WordDocumentBuilder(document);

            //If you have own the password, you can unprotect the document with password
            //builder.Unprotect("password");
            //If you don't own the password, you can unprotect the document without password
            builder.Unprotect();

            File.WriteAllBytes("Unprotected.docx", wordFile.Export(document));
        }
Exemplo n.º 12
0
        public static void AddText()
        {
            WordDocument        document = new WordDocument();
            WordDocumentBuilder builder  = new WordDocumentBuilder(document);

            //Set global style for text and paragraph
            builder.CharacterState.FontFamily      = new ThemableFontFamily("Arial");
            builder.CharacterState.FontSize        = 16;
            builder.ParagraphState.LineSpacing     = 1.2;
            builder.ParagraphState.FirstLineIndent = 40;

            //Insert text using builder directly
            builder.InsertText("Nomal text. ");
            //Insert one line with text, it will add line break automatically
            builder.InsertLine("Nomal line with auto line break. ");
            //So the text below will be added in a second paragraph
            builder.InsertText("Nomal text. ");

            //Insert text using TextInline object
            TextInline textInline = new TextInline(document);

            textInline.Text     = "This text content is using TextInline object. ";
            textInline.FontSize = 20;
            builder.InsertInline(textInline);

            //Insert text with customized style
            builder.InsertText("Times New Roman, ").FontFamily  = new ThemableFontFamily("Times New Roman");
            builder.InsertText("bold, ").FontWeight             = FontWeights.Bold;
            builder.InsertText("italic, ").FontStyle            = FontStyles.Italic;
            builder.InsertText("underline, ").Underline.Pattern = UnderlinePattern.Single;
            builder.InsertText("colors ").ForegroundColor       = new ThemableColor(Color.FromRgb(255, 0, 0));

            //Add several paragraphs to page
            for (int i = 0; i < 20; i++)
            {
                builder.InsertParagraph();
                for (int j = 1; j < 11; j++)
                {
                    builder.InsertText("This is sentence " + j.ToString() + ". ");
                }
            }

            WordFile wordFile = new WordFile();

            using (var stream = File.OpenWrite("AddText.docx"))
            {
                wordFile.Export(document, stream);
            }
        }
Exemplo n.º 13
0
        public static void AddLinkToWebLink()
        {
            WordDocument        document = new WordDocument();
            WordDocumentBuilder builder  = new WordDocumentBuilder(document);

            //Add hyperlink to web url
            builder.InsertHyperlink("this is hyperlink", "http://www.iditect.com", "go to iditect site");

            WordFile wordFile = new WordFile();

            using (var stream = File.OpenWrite("AddLinkToWebLink.docx"))
            {
                wordFile.Export(document, stream);
            }
        }
Exemplo n.º 14
0
        public static void HighlightText()
        {
            WordFile     wordFile = new WordFile();
            WordDocument document = wordFile.Import(File.ReadAllBytes("Sample.docx"));

            WordDocumentBuilder builder = new WordDocumentBuilder(document);

            //Apply new highlight style
            Action <CharacterState> action = new Action <CharacterState>((state) =>
            {
                state.HighlightColor = Colors.Yellow;
            });

            //Highlight all the "Page" text in the document
            builder.ReplaceStyling("Page", true, true, action);

            File.WriteAllBytes("HighlightText.docx", wordFile.Export(document));
        }
Exemplo n.º 15
0
        public static void AddFloatingImage()
        {
            WordDocument        document = new WordDocument();
            WordDocumentBuilder builder  = new WordDocumentBuilder(document);

            builder.CharacterState.FontSize = 24;

            //Add floating image using builder
            using (Stream stream = File.OpenRead("sample.jpg"))
            {
                FloatingImage floatingImage1 = builder.InsertFloatingImage(stream, "jpg");
                floatingImage1.Wrapping.WrappingType = ShapeWrappingType.Square;
            }
            builder.InsertText("This text sentence content will display at the square of the floating image. ");
            builder.InsertText("This text sentence content will display at the square of the floating image.");

            WordFile wordFile = new WordFile();

            File.WriteAllBytes("AddFloatingImage.docx", wordFile.Export(document));
        }
Exemplo n.º 16
0
        public static void InsertDocument()
        {
            WordFile     wordFile = new WordFile();
            WordDocument source   = wordFile.Import(File.ReadAllBytes("source.docx"));
            WordDocument target   = new WordDocument();

            WordDocumentBuilder builder = new WordDocumentBuilder(target);

            builder.CharacterState.FontSize = 30;

            builder.InsertLine("Text start in target document.");

            //Insert the source document just after the first paragraph in the target document
            builder.InsertDocument(source);

            //This line will be appended tight after the source document content
            builder.InsertLine("Text end in target document.");

            File.WriteAllBytes("InsertDocument.docx", wordFile.Export(target));
        }
Exemplo n.º 17
0
        public static void AddHeaderFooterForSections()
        {
            WordDocument        document = new WordDocument();
            WordDocumentBuilder builder  = new WordDocumentBuilder(document);

            //One section can contains a range of pages

            //Insert one section with single page
            Section sectionSinglePage = builder.InsertSection();

            builder.InsertText("First page in section 1");

            //Add header for single page section
            Header headerSinglePage = sectionSinglePage.Headers.Add();

            headerSinglePage.Blocks.AddParagraph().Inlines.AddText("header for single page section");

            //Insert one section with multiple pages
            Section sectionMultipage = builder.InsertSection();

            //Create first page in section
            builder.InsertText("First page in section 2");
            builder.InsertBreak(BreakType.PageBreak);
            //Create second page in section
            builder.InsertText("Second page in section 2");

            //Defaults, all the secions's header and footer will inherit the rules in the first section
            //If you want to use blank header in the second section, you need initialize a new Header object with nothing to do
            Header headerMultipage = sectionMultipage.Headers.Add();
            //Add footer for multiple page section
            Footer footerMultipage = sectionMultipage.Footers.Add();

            footerMultipage.Blocks.AddParagraph().Inlines.AddText("footer for multiple page section");

            WordFile wordFile = new WordFile();

            using (var stream = File.OpenWrite("AddHeaderFooterForSections.docx"))
            {
                wordFile.Export(document, stream);
            }
        }
Exemplo n.º 18
0
        public static void AddLinkInsideDocument()
        {
            WordDocument        document = new WordDocument();
            WordDocumentBuilder builder  = new WordDocumentBuilder(document);

            //Add hyperlink navigate to bookmark inside this document by bookmark's name
            builder.InsertHyperlinkToBookmark("this is hyerlink", "bookmark1", "go to bookmark1");

            //Add a bookmark in the second page
            builder.InsertBreak(BreakType.PageBreak);
            TextInline textBookmark = builder.InsertText("This is bookmark1. ");

            builder.InsertBookmark("bookmark1", textBookmark, textBookmark);

            WordFile wordFile = new WordFile();

            using (var stream = File.OpenWrite("AddLinkInsideDocument.docx"))
            {
                wordFile.Export(document, stream);
            }
        }
Exemplo n.º 19
0
        public static WordDocument CreateMailMergeTemplate()
        {
            WordDocument        document = new WordDocument();
            WordDocumentBuilder builder  = new WordDocumentBuilder(document);

            //Insert salutation
            builder.InsertText("Hello ");
            builder.InsertField("MERGEFIELD CustomerFirstName", "");
            builder.InsertText(" ");
            builder.InsertField("MERGEFIELD CustomerLastName", "");
            builder.InsertText(",");

            //Insert a blank line
            builder.InsertParagraph();

            //Insert mail body
            builder.InsertParagraph();
            builder.InsertText("Thanks for purchasing our ");
            builder.InsertField("MERGEFIELD ProductName ", "");
            builder.InsertText(", please download your Invoice at ");
            builder.InsertField("MERGEFIELD InvoiceURL", "");
            builder.InsertText(". If you have any questions please call ");
            builder.InsertField("MERGEFIELD SupportFhone", "");
            builder.InsertText(", or email us at ");
            builder.InsertField("MERGEFIELD SupportEmail", "");
            builder.InsertText(".");

            //Insert a blank line
            builder.InsertParagraph();

            //Insert mail ending
            builder.InsertParagraph();
            builder.InsertText("Best regards,");
            builder.InsertBreak(BreakType.LineBreak);
            builder.InsertField("MERGEFIELD EmployeeFullname", "");
            builder.InsertText(" ");
            builder.InsertField("MERGEFIELD EmployeeDepartment", "");

            return(document);
        }
Exemplo n.º 20
0
        public static void AddSimpleTable()
        {
            WordDocument        document = new WordDocument();
            WordDocumentBuilder builder  = new WordDocumentBuilder(document);

            builder.TableState.Indent = 100;

            Paragraph tableTitle = builder.InsertParagraph();

            tableTitle.TextAlignment = Alignment.Center;
            builder.InsertLine("Simple Table Title");

            Table table = builder.InsertTable();

            table = CreateSimpleTable(table);

            WordFile wordFile = new WordFile();

            using (var stream = File.OpenWrite("AddSimpleTable.docx"))
            {
                wordFile.Export(document, stream);
            }
        }
Exemplo n.º 21
0
        private void StampaPotvrdaPlacanja()
        {
            //  //string dir = Environment.SpecialFolder.MyDocuments + "\\ServisDB\\";

            string dir = System.IO.Path.Combine(Environment.GetFolderPath(
                                                    Environment.SpecialFolder.MyDoc‌​uments), "ServisDB");

            if (Directory.Exists(dir) == false)
            {
                Directory.CreateDirectory(dir);
            }
            object   o                 = dgvPrijave.SelectedRows[0].DataBoundItem;
            string   rednibroj         = ((DataRowView)o).Row.ItemArray[0].ToString();
            string   kupac             = ((DataRowView)o).Row.ItemArray[5].ToString();
            string   adresa            = ((DataRowView)o).Row.ItemArray[6].ToString();
            string   lk                = ((DataRowView)o).Row.ItemArray[4].ToString();
            string   jmbg              = ((DataRowView)o).Row.ItemArray[3].ToString();
            decimal  inicijalnoplaceno = (decimal)((DataRowView)o).Row.ItemArray[10];
            string   brojrata          = ((DataRowView)o).Row.ItemArray[14].ToString();
            DateTime datum             = (DateTime)((DataRowView)o).Row.ItemArray[1];
            decimal  iznos             = (decimal)((DataRowView)o).Row.ItemArray[13];
            string   napomena          = ((DataRowView)o).Row.ItemArray[18].ToString();
            string   brojracuna        = tbBrojRacuna.Text;
            int      brojrate          = int.Parse(tbBrojRate.Text);
            //decimal inicijalnoplaceno = decimal.Parse(tbInicijalnoUplaceno.Text);
            List <UgovorRata> rate = PersistanceManager.ReadUgovorRata(tbRedniBroj.Text);

            decimal?sumauplata = rate.Sum(r => r.Uplaceno);

            decimal  uplacenoPoRati = decimal.Parse(tbUplaceno.Text);
            DateTime datumPlacanja  = dtpDatumUplate.Value;

            string            uplacenerate = "";
            List <UgovorRata> uplate       = rate.Where(ss => ss.Iznos <= ss.Uplaceno).ToList();

            for (int i = 0; i < uplate.Count; i++)
            {
                uplacenerate = uplacenerate + Environment.NewLine + uplate[i].BrojRate.ToString() + ". " + "rata - uplaćeno: " + uplate[i].Uplaceno.Value.ToString("N2") + "" + " KM ";
            }
            string            neplacenerate = "";
            List <UgovorRata> neplaceneRate = rate.Where(ss => ss.Iznos > ss.Uplaceno).ToList();

            for (int i = 0; i < neplaceneRate.Count; i++)
            {
                neplacenerate = neplacenerate + Environment.NewLine + neplaceneRate[i].BrojRate.ToString() + ". rata" + " do " + neplaceneRate[i].RokPlacanja.ToString("dd.MM.yyyy") + " - iznos od " + neplaceneRate[i].Iznos.ToString("N2") + " KM";
            }

            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict.Add("DATUMPLACANJA", datumPlacanja.ToString("dd.MM.yyyy"));
            dict.Add("IZNOS", uplacenoPoRati.ToString());
            dict.Add("UPLACENERATE", uplacenerate);
            dict.Add("NEPLACENERATE", neplacenerate);
            dict.Add("KUPAC", kupac);
            dict.Add("ADRESA", adresa);
            dict.Add("LK", lk);
            dict.Add("JMBG", jmbg);
            dict.Add("UPLACENO", inicijalnoplaceno.ToString("N2"));
            dict.Add("BROJRATA", brojrata.ToString());
            dict.Add("DATUM", datum.ToString("dd.MM.yyyy"));
            dict.Add("IZNOSRATE", (Math.Round((iznos - inicijalnoplaceno) / int.Parse(brojrata), 2, MidpointRounding.AwayFromZero)).ToString("N2"));
            dict.Add("UKUPANIZNOS", (iznos).ToString("N2"));
            dict.Add("PREDMET", napomena);
            dict.Add("BROJRATE", brojrate.ToString());
            dict.Add("BROJRACUNA", brojracuna);
            dict.Add("BROJUGOVORA", rednibroj);
            dict.Add("INICIJALNOPLACENO", inicijalnoplaceno.ToString("N2"));
            dict.Add("UKUPNOPLACENO", (inicijalnoplaceno + sumauplata.Value).ToString("N2"));
            dict.Add("PREOSTALO", (iznos - inicijalnoplaceno - sumauplata.Value).ToString("N2"));
            string fileName = dir + "\\" + rednibroj.Replace("/", "-") + ".docx";

            WordDocumentBuilder.FillBookmarksUsingOpenXml("PotvrdaPlacanjaRate.docx", fileName, dict);
            Process.Start(fileName);
        }
Exemplo n.º 22
0
        public void CreateDocumentBuilder()
        {
            IDocumentBuilder docBuilder = new WordDocumentBuilder();

            var para = new ParagraphElement(
                new Style {
                ForegroundColor = "green"
            },
                new TextElement("Hello World, this is the paragraph content. "),
                new TextElement(new Style {
                ForegroundColor = "#ff0000"
            }, "This is another text next to the previous one")
                );

            //var para2 = new ParagraphElement(
            //    new TextElement("Hello World, this is the paragraph content. "),
            //    new TextElement("This is another text next to the previous one")
            //);

            var rows = new List <TableRowElement> {
                new TableRowElement(
                    new Style {
                    ForegroundColor = "white",
                    BackgroundColor = "2e2e38",
                    FontName        = FontName,
                    FontSize        = FontSize,
                    Bold            = true
                },
                    new TableCellElement(new ParagraphElement("Hello")),
                    new TableCellElement(new ParagraphElement("World")),
                    new TableCellElement(new ParagraphElement("How")),
                    new TableCellElement(new ParagraphElement("Are")),
                    new TableCellElement(new ParagraphElement("You")),
                    new TableCellElement(new ParagraphElement("Doing"))
                    )
            };

            rows.AddRange(Enumerable.Range(1, 10)
                          .Select(n => new TableRowElement(
                                      new Style
            {
                Border = new Border
                {
                    Color = "444",
                    Type  = BorderType.Thick,
                    Width = 10
                },
                VerticalAlignment = VerticalAlignment.Center,
                BackgroundColor   = n % 2 == 0 ? "#f6f6f6" : null,
                FontName          = FontName,
                FontSize          = FontSize,
                Height            = 70
            },
                                      new TableCellElement(new ParagraphElement("Hello")),
                                      new TableCellElement(new ParagraphElement("World")),
                                      new TableCellElement(new ParagraphElement("How")),
                                      new TableCellElement(new ParagraphElement("Are")),
                                      new TableCellElement(new ParagraphElement("You")),
                                      new TableCellElement(new ParagraphElement("Doing"))
                                      )));

            var table = new TableElement(
                new Style
            {
                Border = new Border
                {
                    Type  = BorderType.Thick,
                    Width = 10,
                    Color = "333333"
                },
                Width = 50
            },
                rows
                );

            docBuilder.Elements.Add(para);
            //docBuilder.Elements.Add(para2);
            docBuilder.Elements.Add(table);
            docBuilder.Elements.Add(new ParagraphElement("\n"));
            docBuilder.Elements.Add(table);


            var bytes = docBuilder.Build();

            File.WriteAllBytes("myfile.docx", bytes);
        }