Exemple #1
0
        public static OpenXmlPowerToolsDocument FromDocument(OpenXmlPowerToolsDocument doc)
        {
            if (doc == null)
            {
                throw new ArgumentNullException(nameof(doc));
            }

            var type = doc.GetDocumentType();

            if (type == typeof(WordprocessingDocument))
            {
                return(new WmlDocument(doc));
            }

            if (type == typeof(SpreadsheetDocument))
            {
                return(new SmlDocument(doc));
            }

            if (type == typeof(PresentationDocument))
            {
                return(new PmlDocument(doc));
            }

            throw new PowerToolsDocumentException("Invalid OpenXmlPowerToolsDocument object");
        }
Exemple #2
0
 public PmlDocument(OpenXmlPowerToolsDocument original)
     : base(original)
 {
     if (GetDocumentType() != typeof(PresentationDocument))
     {
         throw new PowerToolsDocumentException("Not a Presentation document.");
     }
 }
Exemple #3
0
 public SmlDocument(OpenXmlPowerToolsDocument original)
     : base(original)
 {
     if (GetDocumentType() != typeof(SpreadsheetDocument))
     {
         throw new PowerToolsDocumentException("Not a Spreadsheet document.");
     }
 }
Exemple #4
0
 public WmlDocument(OpenXmlPowerToolsDocument original)
     : base(original)
 {
     if (GetDocumentType() != typeof(WordprocessingDocument))
     {
         throw new PowerToolsDocumentException("Not a Wordprocessing document.");
     }
 }
Exemple #5
0
        public OpenXmlPowerToolsDocument(OpenXmlPowerToolsDocument original)
        {
            if (original == null)
            {
                throw new ArgumentNullException(nameof(original));
            }

            DocumentByteArray = new byte[original.DocumentByteArray.Length];
            Array.Copy(original.DocumentByteArray, DocumentByteArray, original.DocumentByteArray.Length);
            FileName = original.FileName;
        }
Exemple #6
0
 public OpenXmlMemoryStreamDocument(OpenXmlPowerToolsDocument doc)
 {
     Document        = doc;
     DocMemoryStream = new MemoryStream();
     DocMemoryStream.Write(doc.DocumentByteArray, 0, doc.DocumentByteArray.Length);
     try
     {
         DocPackage = Package.Open(DocMemoryStream, FileMode.Open);
     }
     catch (Exception e)
     {
         throw new PowerToolsDocumentException(e.Message);
     }
 }
Exemple #7
0
        public OpenXmlPowerToolsDocument(OpenXmlPowerToolsDocument original, bool convertToTransitional)
        {
            if (original == null)
            {
                throw new ArgumentNullException(nameof(original));
            }

            if (convertToTransitional)
            {
                ConvertToTransitional(original.FileName, original.DocumentByteArray);
            }
            else
            {
                DocumentByteArray = new byte[original.DocumentByteArray.Length];
                Array.Copy(original.DocumentByteArray, DocumentByteArray, original.DocumentByteArray.Length);
                FileName = original.FileName;
            }
        }
Exemple #8
0
        public static OpenXmlPowerToolsDocument FromFileName(string fileName)
        {
            var  bytes = File.ReadAllBytes(fileName);
            Type?type;

            try
            {
                type = GetDocumentType(bytes);
            }
            catch (FileFormatException)
            {
                throw new PowerToolsDocumentException("Not an Open XML document.");
            }
            if (type == typeof(WordprocessingDocument))
            {
                return(new WmlDocument(fileName, bytes));
            }

            if (type == typeof(SpreadsheetDocument))
            {
                return(new SmlDocument(fileName, bytes));
            }

            if (type == typeof(PresentationDocument))
            {
                return(new PmlDocument(fileName, bytes));
            }

            if (type == typeof(Package))
            {
                var pkg = new OpenXmlPowerToolsDocument(bytes)
                {
                    FileName = fileName
                };
                return(pkg);
            }
            throw new PowerToolsDocumentException("Not an Open XML document.");
        }