コード例 #1
0
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        DocumentModel document = new DocumentModel();

        // Set the content for the whole document
        document.Content.LoadText("Paragraph 1\nParagraph 2\nParagraph 3\nParagraph 4\nParagraph 5");

        var bold = new CharacterFormat()
        {
            Bold = true
        };

        // Set the content for the 2nd paragraph
        document.Sections[0].Blocks[1].Content.LoadText("Bold paragraph 2", bold);

        // Set the content for 3rd and 4th paragraph to be the same as the content of 1st and 2nd paragraph
        var para3            = document.Sections[0].Blocks[2];
        var para4            = document.Sections[0].Blocks[3];
        var destinationRange = new ContentRange(para3.Content.Start, para4.Content.End);
        var para1            = document.Sections[0].Blocks[0];
        var para2            = document.Sections[0].Blocks[1];
        var sourceRange      = new ContentRange(para1.Content.Start, para2.Content.End);

        destinationRange.Set(sourceRange);

        // Set content using HTML tags
        document.Sections[0].Blocks[4].Content.LoadText("Paragraph 5 <b>(part of this paragraph is bold)</b>", LoadOptions.HtmlDefault);

        document.Save("Set Content.docx");
    }
コード例 #2
0
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var document = new DocumentModel();

        // Set the content for the whole document.
        document.Content.LoadText("First paragraph.\nSecond paragraph.\nThird paragraph.\nFourth paragraph.\nFifth paragraph.");

        var section = document.Sections[0];

        // Set the content for 1st paragraph using plain text.
        section.Blocks[0].Content.LoadText("Paragraph with plain text.");

        // Set the content for 2nd paragraph using specified formatting.
        section.Blocks[1].Content.LoadText("Paragraph with red and bold text.",
                                           new CharacterFormat()
        {
            FontColor = Color.Red, Bold = true
        });

        var sourceRange = new ContentRange(
            section.Blocks[0].Content.Start,
            section.Blocks[1].Content.End);

        var destinationRange = new ContentRange(
            section.Blocks[2].Content.Start,
            section.Blocks[3].Content.End);

        // Set the content for 3rd and 4th paragraph to be the same as the content of 1st and 2nd paragraph.
        destinationRange.Set(sourceRange);

        // Set the content for 5th paragraph using HTML text.
        section.Blocks[4].Content.LoadText("<p style='font:11pt Calibri;color:blue;'>Paragraph with blue text that has <i>italic part</i>.</p>",
                                           new HtmlLoadOptions());

        document.Save("Set Content.docx");
    }
コード例 #3
0
        /// <summary>
        /// Создание документа форд
        /// </summary>
        /// <param name="client">Массив с данными. для записи в Word</param>
        /// <param name="paht">paht Путь к файлу. Куда сохранять</param>
        /// <param name="nameClient">Id имя клиента </param>
        public void GetBoxCreateWordAndPdf(string[] client, string paht, int IdClient)
        {
            string hedstr = @"
Касса №1 — сеть центров выдачи займов!
kassaone.ru
Сеть центров по выдаче денежных займов размещает условия предоставления денежных средств частным лицам." + Environment.NewLine;

            // создание ссылок дирикторий(папок для картинки). Корневая папка
            // var originalDirectory = new DirectoryInfo(string.Format(@"~Archive_Documents\\Uploads"));

            //Тест переменная


            string temp;
            string ext;
            string tempPahtImag;

            //Бесплатное Лицензия
            ComponentInfo.SetLicense("FREE-LIMITED-KEY");

            // Создание нового дока.
            var document = new DocumentModel();

            try
            {
                //Цикл для записи текста вфайл ворд
                for (int i = 0; i < client.Length; i++)
                {
                    hedstr += (client[i] + Environment.NewLine);
                }
                ;

                document.Content.LoadText(hedstr);

                document.Save(paht + $@"\\Result_Client_{IdClient}.docx");
                document.Save(paht + $@"\\Result_Client_{IdClient}.pdf");

                //поиск и замена Картинки.
                ContentRange imagePlaceholder = document.Content.Find("#IMAGE").First();

                //дергаем из Бд имя и путь картнки
                using (DBContext db = new DBContext())
                {
                    temp = db.clients.Find(IdClient).imagePathInDoc;
                }

                //получаем разширение
                ext = System.IO.Path.GetExtension(temp);

                //Получаем имя файла
                tempPahtImag = System.IO.Path.GetFileName(temp);

                //проверка разширения
                if (ext != "image/jpg" &&
                    ext != "image/jpeg" &&
                    ext != "image/pjpeg" &&
                    ext != "image/gif" &&
                    ext != "image/png" &&
                    ext != "image/x-png")
                {
                }

                string pathCopy = paht + "\\" + tempPahtImag;
                File.Copy(temp, pathCopy, true);

                imagePlaceholder.Set(new Picture(document, paht + $"\\{tempPahtImag}").Content);

                //создаем документ в 2х форматах. *.docx и *.pdf
                document.Save(paht + $@"\\Result_Client_{IdClient.ToString()}.docx");
                document.Save(paht + $@"\\Result_Client_{IdClient.ToString()}.pdf");
            }

            catch (Exception ex)
            {
                JournalLog(ex.ToString());
                //для лога ошибок
            }
        }