コード例 #1
0
ファイル: DocumentCreator.cs プロジェクト: SahsaB/pk
        public static void Create(DB_Connector connection, string templateFile, string resultFile, uint id, bool readOnly = false)
        {
            #region Contracts
            CheckConnectionAndFilenames(connection, templateFile, resultFile);
            #endregion

            XDocument template = XDocument.Load(templateFile, LoadOptions.PreserveWhitespace);

            Validate(template);

            if (template.Root.Element("Document").Element("Word") != null)
            {
                Novacode.DocX doc = Word.CreateFromTemplate(connection, GetFonts(template.Root.Element("Fonts")), template.Root.Element("Document").Element("Word"), id, resultFile);

                if (readOnly)
                {
                    doc.AddProtection(Novacode.EditRestrictions.readOnly);
                }
                doc.Save();
            }
            else
            {
                throw new System.ArgumentException("Эта перегрузка принимат только тип шаблона \"Word\".", nameof(templateFile));
            }
        }
コード例 #2
0
ファイル: DocumentCreator.cs プロジェクト: SahsaB/pk
        public static void Create(string resultFile, IEnumerable <DocumentParameters> documents, bool readOnly = false)
        {
            #region Contracts
            if (string.IsNullOrWhiteSpace(resultFile))
            {
                throw new System.ArgumentException("Некорректное имя выходного файла.", nameof(resultFile));
            }
            if (System.Linq.Enumerable.Count(documents) == 0)
            {
                throw new System.ArgumentException("Коллекция с документами должна содержать хотя бы один элемент.", nameof(documents));
            }
            #endregion

            Novacode.DocX doc = null;
            foreach (var document in documents)
            {
                XDocument template = XDocument.Load(document.Template, LoadOptions.PreserveWhitespace);

                Validate(template);

                if (template.Root.Element("Document").Element("Word") != null)
                {
                    Novacode.DocX buf;
                    if (document.Connection != null)
                    {
                        buf = Word.CreateFromTemplate(document.Connection, GetFonts(template.Root.Element("Fonts")), template.Root.Element("Document").Element("Word"), document.ID.Value, resultFile);
                    }
                    else
                    {
                        buf = Word.CreateFromTemplate(GetFonts(template.Root.Element("Fonts")), template.Root.Element("Document").Element("Word"), document.SingleParameters, document.TableParameters, resultFile);
                    }

                    if (doc == null)
                    {
                        doc = buf;
                    }
                    else
                    {
                        doc.InsertSectionPageBreak();
                        doc.InsertDocument(buf);
                    }
                }
                else
                {
                    throw new System.ArgumentException("Эта перегрузка принимат только тип шаблонов \"Word\".", nameof(documents));
                }

                if (readOnly)
                {
                    doc.AddProtection(Novacode.EditRestrictions.readOnly);
                }
                doc.Save();
            }
        }
コード例 #3
0
        public void AddParagraph()
        {
            Novacode.DocX         d = Novacode.DocX.Create("thing.docx");
            List <List <string> > p = new List <List <string> >();

            p.Add(new List <string>());
            p[0].Add("let's get TeXy with {1} and {2}");
            p[0].Add("\\textbf{Bold bits}");
            p[0].Add("\\textit{italic bits}");
            WordifyThings.AddParagraph(p, d);

            d.Save();
        }
コード例 #4
0
        public void rlapTest()
        {
            Novacode.DocX         d   = Novacode.DocX.Create(@"rlap.docx");
            List <List <string> > tex = new List <List <string> >();

            tex.Add(new List <string>());

            tex[0].Add("`This is a quoted sentence{0}");
            tex[0].Add("\\rlap{.}{'}");

            WordifyThings.AddParagraph(tex, d);
            d.Save();
        }
コード例 #5
0
ファイル: DocumentCreator.cs プロジェクト: SahsaB/pk
        public static void Create(string templateFile, string resultFile, string[] singleParams, IEnumerable <string[]>[] tableParams, bool readOnly = false)
        {
            #region Contracts
            CheckFilenames(templateFile, resultFile);
            if (singleParams == null && tableParams == null)
            {
                throw new System.ArgumentException("Необходимо передать хотя бы один одиночный или табличный параметр.");
            }
            if (singleParams != null && singleParams.Length == 0)
            {
                throw new System.ArgumentException("Массив с одиночными параметрами должен содержать хотя бы один элемент.", nameof(singleParams));
            }
            if (tableParams != null && tableParams.Length == 0)
            {
                throw new System.ArgumentException("Массив с табличными параметрами должен содержать хотя бы один элемент.", nameof(tableParams));
            }
            #endregion

            XDocument template = XDocument.Load(templateFile, LoadOptions.PreserveWhitespace);

            Validate(template);

            if (template.Root.Element("Document").Element("Word") != null)
            {
                Novacode.DocX doc = Word.CreateFromTemplate(GetFonts(template.Root.Element("Fonts")), template.Root.Element("Document").Element("Word"), singleParams, tableParams, resultFile);

                if (readOnly)
                {
                    doc.AddProtection(Novacode.EditRestrictions.readOnly);
                }
                doc.Save();
            }
            else
            {
                throw new System.ArgumentException("Эта перегрузка принимат только тип шаблона \"Word\".", nameof(templateFile));
            }
        }