public static void AddList(List list, Docx.DocX doc)
        {
            // TODO: Figure this out. ListItems require a paragraph
            // to add, but the paragraph constructor is private. ??

            /*
             * Docx.ListItemType listType;
             * if (list.MarkerStyle == TextMarkerStyle.Disc)
             * {
             *  listType = Docx.ListItemType.Bulleted;
             * }
             * else
             * {
             *  listType = Docx.ListItemType.Numbered;
             * }
             *
             * Docx.List dList = doc.AddList(listType: listType);
             * foreach (var item in list.ListItems)
             * {
             *  foreach (var block in item.Blocks)
             *  {
             *      AddBlock(block, doc);
             *  }
             * }*/
        }
示例#2
0
        public void ExportToWord(Docx.DocX doc)
        {
            // Skip encrypted scenes.
            var scenes = Scenes.Where(i => !i.IsEncrypted).OrderBy(i => i.SortIndex).ToList();

            if (scenes.Count > 0)
            {
                // Export chapter name.
                Xceed.Document.NET.Paragraph chapterHeader = doc.InsertParagraph();
                chapterHeader.StyleId = "Heading1";
                chapterHeader.Append(Model.Name);

                doc.InsertParagraph();
                doc.InsertParagraph();
                doc.InsertParagraph();

                for (int i = 0; i < scenes.Count; i++)
                {
                    SceneViewModel scene = scenes[i];
                    scene.ExportToWord(doc);
                    if (i < Scenes.Count - 1)
                    {
                        Xceed.Document.NET.Paragraph p = doc.InsertParagraph();
                        p.StyleId = "SceneBreak";
                        p.Append("\n*\t\t*\t\t*\n");
                    }
                }
                doc.Paragraphs.Last().InsertPageBreakAfterSelf();
            }
        }
 public static void AddParagraph(Paragraph paragraph, Docx.DocX doc)
 {
     Xceed.Document.NET.Paragraph p = doc.InsertParagraph();
     foreach (var inline in paragraph.Inlines)
     {
         AddInline(inline, p);
     }
 }
 public static void ExportItem(IExportToWordDocument item, string outputPath, string templatePath)
 {
     using (Docx.DocX doc = Docx.DocX.Create(outputPath))
     {
         if (templatePath != null)
         {
             doc.ApplyTemplate(templatePath);
         }
         item.ExportToWord(doc);
         doc.Save();
     }
 }
 public static void AddBlock(Block block, Docx.DocX doc)
 {
     if (block is Paragraph)
     {
         Paragraph p = (Paragraph)block;
         FlowDocumentExporter.AddParagraph(p, doc);
     }
     else if (block is List)
     {
         List list = (List)block;
         AddList(list, doc);
     }
 }
示例#6
0
        public void ExportToWord(Docx.DocX doc)
        {
            FlowDocument flowDoc = new FlowDocument(Model.Connection);

            flowDoc.id = Model.FlowDocumentId;
            flowDoc.Load();

            FlowDocumentViewModel vm = new FlowDocumentViewModel(flowDoc, DialogOwner);

            foreach (WinDoc.Block block in vm.Document.Blocks)
            {
                if (block is WinDoc.Paragraph)
                {
                    FlowDocumentExporter.AddParagraph((WinDoc.Paragraph)block, doc);
                }
            }
        }
示例#7
0
        private void GenerateReportItem(XC.DocX doc, IReportItem reportItem, int level, CancellationToken cancellationToken, IProgress <string> progress)
        {
            var blockBuilder = _blockBuilderFactory.GetBlockBuilder(doc, reportItem);

            blockBuilder.Build(reportItem, level, cancellationToken, progress);

            var testCases = reportItem.Children.OfType <TestCase>();

            foreach (var testCase in testCases)
            {
                GenerateReportItem(doc, testCase, level + 1, cancellationToken, progress);
            }

            var testSuites = reportItem.Children.OfType <TestSuite>();

            foreach (var testSuite in testSuites)
            {
                GenerateReportItem(doc, testSuite, level + 1, cancellationToken, progress);
            }
        }
示例#8
0
 protected Container(DocX document, XElement xml)
     : base(document, xml)
 {
 }
示例#9
0
        public void ExportToWord(Docx.DocX doc)
        {
            // Format title page of the document.
            Xceed.Document.NET.Paragraph p = doc.InsertParagraph();
            p.Append("\n\n" + Model.Name);
            p.StyleId = "Title";

            if (!string.IsNullOrWhiteSpace(Model.Subtitle))
            {
                p = doc.InsertParagraph();
                p.Append(Model.Subtitle);
                p.StyleId = "Subtitle";
            }
            if (!string.IsNullOrWhiteSpace(Model.Author))
            {
                p = doc.InsertParagraph();
                p.Append("\n\n" + Model.Author);
                p.StyleId = "Subtitle";
            }
            p.InsertPageBreakAfterSelf();

            // Insert copyright page.
            if (Model.FlowDocumentId.HasValue)
            {
                FlowDocument copyrightFd = new FlowDocument(Model.Connection);
                copyrightFd.id = Model.FlowDocumentId.Value;
                copyrightFd.Load();

                FlowDocumentViewModel copyrightVm = new FlowDocumentViewModel(copyrightFd, DialogOwner);

                foreach (WinDoc.Block block in copyrightVm.Document.Blocks)
                {
                    if (block is WinDoc.Paragraph)
                    {
                        FlowDocumentExporter.AddParagraph((WinDoc.Paragraph)block, doc);
                    }
                }

                p.InsertPageBreakAfterSelf();
            }

            // Insert eBook table of contents.

            // This doesn't make sense to me. Xceed's documentation says "A key-value dictionary where the key is a TableOfContentSwitches
            // and the value is the parameter of the switch."
            // I have no idea what the string values are supposed to be. Empty strings seem to work.
            Dictionary <Xceed.Document.NET.TableOfContentsSwitches, string> tocParams = new Dictionary <Xceed.Document.NET.TableOfContentsSwitches, string>();

            tocParams[Xceed.Document.NET.TableOfContentsSwitches.H] = ""; // TOC entries are clickable hyperlinks.
            tocParams[Xceed.Document.NET.TableOfContentsSwitches.N] = ""; // Omits page numbers.
            tocParams[Xceed.Document.NET.TableOfContentsSwitches.Z] = ""; // Hides tab leader and page numbers...?
            tocParams[Xceed.Document.NET.TableOfContentsSwitches.U] = ""; // Uses the applied paragraph outline level...?
            Xceed.Document.NET.TableOfContents toc = doc.InsertTableOfContents("Table of Contents", tocParams);
            doc.Paragraphs.Last().InsertPageBreakAfterSelf();

            for (int i = 0; i < Chapters.Count; i++)
            {
                ChapterViewModel chapter = Chapters[i];
                chapter.ExportToWord(doc);
            }
        }
示例#10
0
文件: DocX.cs 项目: zwdwww/DocX
        /// <summary>
        /// Copy the Document into a new Document
        /// </summary>
        /// <returns>Returns a copy of a the Document</returns>
        public override Xceed.Document.NET.Document Copy()
        {
            var initialDoc = !string.IsNullOrEmpty(_filename) ? DocX.Load(_filename) : DocX.Load(_stream);

            var memorystream = new MemoryStream();

            initialDoc.SaveAs(memorystream);

            memorystream.Seek(0, SeekOrigin.Begin);
            return(DocX.Load(memorystream));
        }
示例#11
0
 internal Header(DocX document, XElement xml, PackagePart mainPart) : base(document, xml)
 {
     this.PackagePart = mainPart;
 }
示例#12
0
 private bool HasStyle(DocX document, string value, string type)
 {
     return(document._styles.Descendants().Any(x => x.Name.Equals(DocX.w + "style") && (x.Attribute(DocX.w + "type") == null || x.Attribute(DocX.w + "type").Value.Equals(type)) && x.Attribute(DocX.w + "styleId") != null && x.Attribute(DocX.w + "styleId").Value.Equals(value)));
 }
示例#13
0
 internal List(DocX document, XElement xml)
     : base(document, xml)
 {
     Items    = new List <Paragraph>();
     ListType = null;
 }
示例#14
0
 public InsertBeforeOrAfter(DocX document, XElement xml)
     : base(document, xml)
 {
 }
示例#15
0
        internal DocProperty(DocX document, XElement xml) : base(document, xml)
        {
            var instr = Xml.Attribute(XName.Get("instr", "http://schemas.openxmlformats.org/wordprocessingml/2006/main")).Value;

            this.Name = _extractName.Match(instr.Trim()).Groups["name"].Value;
        }
示例#16
0
        /// <summary>
        /// Loads a document into a Document object using a Stream.
        /// </summary>
        /// <param name="stream">The Stream to load the document from.</param>
        /// <returns>
        /// Returns a Document object which represents the document.
        /// </returns>
        /// <example>
        /// Loading a document from a FileStream.
        /// <code>
        /// // Open a FileStream fs to a document.
        /// using (FileStream fs = new FileStream(@"C:\Example\Test.docx", FileMode.Open))
        /// {
        ///     // Load the document using fs.
        ///     using (var document = DocX.Load(fs))
        ///     {
        ///         // Do something with the document here.
        ///
        ///         // Save all changes made to the document.
        ///         document.Save();
        ///     }// Release this document from memory.
        /// }
        /// </code>
        /// </example>
        /// <example>
        /// Loading a document from a SharePoint site.
        /// <code>
        /// // Get the SharePoint site that you want to access.
        /// using (SPSite mySite = new SPSite("http://server/sites/site"))
        /// {
        ///     // Open a connection to the SharePoint site
        ///     using (SPWeb myWeb = mySite.OpenWeb())
        ///     {
        ///         // Grab a document stored on this site.
        ///         SPFile file = web.GetFile("Source_Folder_Name/Source_File");
        ///
        ///         // Document.Load requires a Stream, so open a Stream to this document.
        ///         Stream str = new MemoryStream(file.OpenBinary());
        ///
        ///         // Load the file using the Stream str.
        ///         using (var document = DocX.Load(str))
        ///         {
        ///             // Do something with the document here.
        ///
        ///             // Save all changes made to the document.
        ///             document.Save();
        ///         }// Release this document from memory.
        ///     }
        /// }
        /// </code>
        /// </example>
        /// <seealso cref="DocX.Load(string)"/>
        /// <seealso cref="DocX.Save()"/>
        public static DocX Load(Stream stream)
        {
            var docX = new DocX(null, null) as Xceed.Document.NET.Document;

            return(Xceed.Document.NET.Document.Load(stream, docX, DocumentTypes.Document) as DocX);
        }
示例#17
0
 internal Image(DocX document, PackageRelationship pr)
 {
     _document = document;
     _pr       = pr;
     _id       = pr.Id;
 }
示例#18
0
 private TableOfContents(DocX document, XElement xml, string headerStyle)
     : base(document, xml)
 {
     InitElement("updateFields", document);
     InitElement("styles", document, headerStyle);
 }
示例#19
0
        /// <summary>
        /// Wraps an XElement as an Image
        /// </summary>
        /// <param name="document"></param>
        /// <param name="i">The XElement i to wrap</param>
        /// <param name="image"></param>
        internal Picture(DocX document, XElement i, Image image) : base(document, i)
        {
            _picture_rels = new Dictionary <PackagePart, PackageRelationship>();

            _img = image;

            var imageId =
                (
                    from e in Xml.Descendants()
                    where e.Name.LocalName.Equals("blip")
                    select e.Attribute(XName.Get("embed", "http://schemas.openxmlformats.org/officeDocument/2006/relationships")).Value
                ).SingleOrDefault();

            _id = (imageId != null)
           ? imageId
           : (
                from e in Xml.Descendants()
                where e.Name.LocalName.Equals("imagedata")
                select e.Attribute(XName.Get("id", "http://schemas.openxmlformats.org/officeDocument/2006/relationships")).Value
                ).SingleOrDefault();

            var nameToFind =
                (
                    from e in Xml.Descendants()
                    let a = e.Attribute(XName.Get("name"))
                            where (a != null)
                            select a.Value
                ).FirstOrDefault();

            _name = (nameToFind != null)
             ? nameToFind
             : (
                from e in Xml.Descendants()
                let a = e.Attribute(XName.Get("title"))
                        where (a != null)
                        select a.Value
                ).FirstOrDefault();

            _descr =
                (
                    from e in Xml.Descendants()
                    let a = e.Attribute(XName.Get("descr"))
                            where (a != null)
                            select a.Value
                ).FirstOrDefault();

            _cx =
                (
                    from e in Xml.Descendants()
                    let a = e.Attribute(XName.Get("cx"))
                            where (a != null)
                            select int.Parse(a.Value)
                ).FirstOrDefault();

            if (_cx == 0)
            {
                var style =
                    (
                        from e in Xml.Descendants()
                        let a = e.Attribute(XName.Get("style"))
                                where (a != null)
                                select a
                    ).FirstOrDefault();

                if (style != null)
                {
                    var widthString      = style.Value.Substring(style.Value.IndexOf("width:") + 6);
                    var widthValueString = widthString.Substring(0, widthString.IndexOf("pt")).Replace(".", ",");
                    var widthDouble      = (double.Parse(widthValueString) / 72d) * 914400;
                    _cx = System.Convert.ToInt32(widthDouble);
                }
            }

            _cy =
                (
                    from e in Xml.Descendants()
                    let a = e.Attribute(XName.Get("cy"))
                            where (a != null)
                            select int.Parse(a.Value)
                ).FirstOrDefault();

            if (_cy == 0)
            {
                var style =
                    (
                        from e in Xml.Descendants()
                        let a = e.Attribute(XName.Get("style"))
                                where (a != null)
                                select a
                    ).FirstOrDefault();

                if (style != null)
                {
                    var heightString      = style.Value.Substring(style.Value.IndexOf("height:") + 7);
                    var heightValueString = heightString.Substring(0, heightString.IndexOf("pt")).Replace(".", ",");
                    var heightDouble      = (double.Parse(heightValueString) / 72d) * 914400;
                    _cy = System.Convert.ToInt32(heightDouble);
                }
            }

            _xfrm =
                (
                    from d in Xml.Descendants()
                    where d.Name.LocalName.Equals("xfrm")
                    select d
                ).SingleOrDefault();

            _prstGeom =
                (
                    from d in Xml.Descendants()
                    where d.Name.LocalName.Equals("prstGeom")
                    select d
                ).SingleOrDefault();

            if (_xfrm != null)
            {
                _rotation = _xfrm.Attribute(XName.Get("rot")) == null ? 0 : uint.Parse(_xfrm.Attribute(XName.Get("rot")).Value);
            }
        }
示例#20
0
        /// <summary>
        /// Loads a document into a Document object using a fully qualified or relative filename.
        /// </summary>
        /// <param name="filename">The fully qualified or relative filename.</param>
        /// <returns>
        /// Returns a DocX object which represents the document.
        /// </returns>
        /// <example>
        /// <code>
        /// // Load a document using its fully qualified filename
        /// using (var document = DocX.Load(@"C:\Example\Test.docx"))
        /// {
        ///     // Do something with the document here
        ///
        ///     // Save all changes made to document.
        ///     document.Save();
        /// }// Release this document from memory.
        /// </code>
        /// <code>
        /// // Load a document using its relative filename.
        /// using(var document = DocX.Load(@"..\..\Test.docx"))
        /// {
        ///     // Do something with the document here.
        ///
        ///     // Save all changes made to document.
        ///     document.Save();
        /// }// Release this document from memory.
        /// </code>
        /// </example>
        public static DocX Load(string filename)
        {
            var docX = new DocX(null, null) as Xceed.Document.NET.Document;

            return(Xceed.Document.NET.Document.Load(filename, docX, DocumentTypes.Document) as DocX);
        }
示例#21
0
文件: DocX.cs 项目: vborovikov/DocX
        public override void SaveAs(string filename)
        {
            if (this.IsPackageClosed(_package))
            {
                // When package is closed (already saved), reload the package and restart SaveAs();
                var initialDoc = !string.IsNullOrEmpty(_filename) ? DocX.Load(_filename) : DocX.Load(_stream);
                initialDoc.SaveAs(filename);
                return;
            }

            base.SaveAs(filename);
        }
示例#22
0
 internal Container(DocX document, XElement xml)
     : base(document, xml)
 {
 }
示例#23
0
文件: DocX.cs 项目: vborovikov/DocX
        /// <summary>
        /// Save this document back to the location it was loaded from.
        /// </summary>
        /// <example>
        /// <code>
        /// // Load a document.
        /// using (var document = DocX.Load(@"C:\Example\Test.docx"))
        /// {
        ///     // Add an Image from a file.
        ///     document.AddImage(@"C:\Example\Image.jpg");
        ///
        ///     // Save all changes made to this document.
        ///     document.Save();
        /// }// Release this document from memory.
        /// </code>
        /// </example>
        /// <seealso cref="DocX.Load(System.IO.Stream)"/>
        /// <seealso cref="DocX.Load(string)"/>
        /// <!--
        /// Bug found and fixed by krugs525 on August 12 2009.
        /// Use TFS compare to see exact code change.
        /// -->
        public override void Save()
        {
            if (this.IsPackageClosed(_package))
            {
                // When package is closed (already saved), reload the package and restart Save();
                var initialDoc = !string.IsNullOrEmpty(_filename) ? DocX.Load(_filename) : DocX.Load(_stream);
                initialDoc.Save();
                return;
            }

            // Save the main document
            using (TextWriter tw = new StreamWriter(new PackagePartStream(this.PackagePart.GetStream(FileMode.Create, FileAccess.Write))))
            {
                _mainDoc.Save(tw, SaveOptions.None);
            }

            if ((_settings == null) || !this.isProtected)
            {
                using (TextReader textReader = new StreamReader(_settingsPart.GetStream()))
                {
                    _settings = XDocument.Load(textReader);
                }
            }

            // Save the header/footer content.
            this.SaveHeadersFooters();

            // Save the settings document.
            using (TextWriter tw = new StreamWriter(new PackagePartStream(_settingsPart.GetStream(FileMode.Create, FileAccess.Write))))
            {
                _settings.Save(tw, SaveOptions.None);
            }

            if (_endnotesPart != null)
            {
                using (TextWriter tw = new StreamWriter(new PackagePartStream(_endnotesPart.GetStream(FileMode.Create, FileAccess.Write))))
                {
                    _endnotes.Save(tw, SaveOptions.None);
                }
            }

            if (_footnotesPart != null)
            {
                using (TextWriter tw = new StreamWriter(new PackagePartStream(_footnotesPart.GetStream(FileMode.Create, FileAccess.Write))))
                {
                    _footnotes.Save(tw, SaveOptions.None);
                }
            }

            if (_stylesPart != null)
            {
                using (TextWriter tw = new StreamWriter(new PackagePartStream(_stylesPart.GetStream(FileMode.Create, FileAccess.Write))))
                {
                    _styles.Save(tw, SaveOptions.None);
                }
            }

            if (_stylesWithEffectsPart != null)
            {
                using (TextWriter tw = new StreamWriter(new PackagePartStream(_stylesWithEffectsPart.GetStream(FileMode.Create, FileAccess.Write))))
                {
                    _stylesWithEffects.Save(tw, SaveOptions.None);
                }
            }

            if (_numberingPart != null)
            {
                using (TextWriter tw = new StreamWriter(new PackagePartStream(_numberingPart.GetStream(FileMode.Create, FileAccess.Write))))
                {
                    _numbering.Save(tw, SaveOptions.None);
                }
            }

            if (_fontTablePart != null)
            {
                using (TextWriter tw = new StreamWriter(new PackagePartStream(_fontTablePart.GetStream(FileMode.Create, FileAccess.Write))))
                {
                    _fontTable.Save(tw, SaveOptions.None);
                }
            }

            // Close the document so that it can be saved in .NETStandard.
            _package.Close();

            #region Save this document back to a file or stream, that was specified by the user at save time.
            if (_filename != null)
            {
                var saveFileName = _filename.EndsWith(".docx") || _filename.EndsWith(".doc") ? _filename : _filename + ".docx";
                using (FileStream fs = new FileStream(saveFileName, FileMode.Create))
                {
                    if (_memoryStream.CanSeek)
                    {
                        // Write to the beginning of the stream
                        _memoryStream.Position = 0;
                        HelperFunctions.CopyStream(_memoryStream, fs);
                    }
                    else
                    {
                        fs.Write(_memoryStream.ToArray(), 0, (int)_memoryStream.Length);
                    }
                }
            }
            else if (_stream.CanSeek) //Check if stream can be seeked to support System.Web.HttpResponseStream.
            {
                // Set the length of this stream to 0
                _stream.SetLength(0);

                // Write to the beginning of the stream
                _stream.Position = 0;

                _memoryStream.WriteTo(_stream);
                _memoryStream.Flush();
            }
            #endregion
        }
示例#24
0
 /// <summary>
 /// Store both the document and xml so that they can be accessed by derived types.
 /// </summary>
 /// <param name="document">The document that this element belongs to.</param>
 /// <param name="xml">The Xml that gives this element substance</param>
 public DocXElement(DocX document, XElement xml)
 {
     this.Document = document;
     this.Xml      = xml;
 }
示例#25
0
文件: DocX.cs 项目: vborovikov/DocX
        /// <summary>
        /// Copy the Document into a new Document
        /// </summary>
        /// <returns>Returns a copy of a the Document</returns>
        public override Xceed.Document.NET.Document Copy()
        {
            try
            {
                var initialDoc = this;
                if (this.IsPackageClosed(_package))
                {
                    initialDoc = !string.IsNullOrEmpty(_filename) ? DocX.Load(_filename) : DocX.Load(_stream);
                }

                var memorystream = new MemoryStream();
                initialDoc.SaveAs(memorystream);

                memorystream.Seek(0, SeekOrigin.Begin);
                return(DocX.Load(memorystream));
            }
            catch (Exception e)
            {
                // If we can't load the filename or stream, just return the current document.
                return(this);
            }
        }
示例#26
0
 internal PageLayout(DocX document, XElement xml) : base(document, xml)
 {
 }
示例#27
0
文件: Section.cs 项目: zyfzgt/DocX
 internal Section(DocX document, XElement xml) : base(document, xml)
 {
 }