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"); }
public PmlDocument(OpenXmlPowerToolsDocument original) : base(original) { if (GetDocumentType() != typeof(PresentationDocument)) { throw new PowerToolsDocumentException("Not a Presentation document."); } }
public SmlDocument(OpenXmlPowerToolsDocument original) : base(original) { if (GetDocumentType() != typeof(SpreadsheetDocument)) { throw new PowerToolsDocumentException("Not a Spreadsheet document."); } }
public WmlDocument(OpenXmlPowerToolsDocument original) : base(original) { if (GetDocumentType() != typeof(WordprocessingDocument)) { throw new PowerToolsDocumentException("Not a Wordprocessing document."); } }
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; }
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); } }
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; } }
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."); }