Esempio n. 1
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);
                pkg.FileName = fileName;
                return(pkg);
            }
            throw new PowerToolsDocumentException("Not an Open XML document.");
        }
Esempio n. 2
0
 public PmlDocument(OpenXmlPowerToolsDocument original)
     : base(original)
 {
     if (GetDocumentType() != typeof(PresentationDocument))
     {
         throw new PowerToolsDocumentException("Not a Presentation document.");
     }
 }
Esempio n. 3
0
 public SmlDocument(OpenXmlPowerToolsDocument original)
     : base(original)
 {
     if (GetDocumentType() != typeof(SpreadsheetDocument))
     {
         throw new PowerToolsDocumentException("Not a Spreadsheet document.");
     }
 }
Esempio n. 4
0
 public WmlDocument(OpenXmlPowerToolsDocument original)
     : base(original)
 {
     if (GetDocumentType() != typeof(WordprocessingDocument))
     {
         throw new PowerToolsDocumentException("Not a Wordprocessing document.");
     }
 }
Esempio n. 5
0
 public OpenXmlMemoryStreamDocument(OpenXmlPowerToolsDocument doc)
 {
     Document        = doc;
     DocMemoryStream = new MemoryStream();
     doc.WriteByteArray(DocMemoryStream);
     try
     {
         DocPackage = Package.Open(DocMemoryStream, FileMode.Open);
     }
     catch (Exception)
     {
         throw new PowerToolsDocumentException("Not an Open XML document.");
     }
 }
Esempio n. 6
0
        public static OpenXmlPowerToolsDocument FromDocument(OpenXmlPowerToolsDocument 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));
            }
            return(null);    // This should not be possible from a valid OpenXmlPowerToolsDocument object
        }
Esempio n. 7
0
 public OpenXmlPowerToolsDocument(OpenXmlPowerToolsDocument original)
 {
     DocumentByteArray = new byte[original.DocumentByteArray.Length];
     Array.Copy(original.DocumentByteArray, DocumentByteArray, original.DocumentByteArray.Length);
     FileName = original.FileName;
 }