Exemplo n.º 1
0
        /// <summary>
        /// Creates a new document using the supplied stream, type and autosave value
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="type"></param>
        /// <param name="autoSave"></param>
        /// <returns></returns>
        public static DocX Create(Stream stream, DocumentType type, bool autoSave)
        {
            var docX = new DocX();

            docX.Create(WordprocessingDocument.Create(stream, Convert.ToWordprocessingDocumentType(type), autoSave));

            return(docX);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new document using the supplied template
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static DocX CreateFromTemplate(string path)
        {
            var docX = new DocX();

            var tempFile = Path.GetTempFileName();

            File.Delete(tempFile);
            File.Copy(path, tempFile);

            var doc = WordprocessingDocument.Open(tempFile, true);

            doc.ChangeDocumentType(WordprocessingDocumentType.Document);

            docX.Create(doc, createFromTemplate: true);

            return(docX);
        }