public static string[] TableNames(SmlDocument smlDoc)
 {
     using var ms = new MemoryStream();
     ms.Write(smlDoc.DocumentByteArray, 0, smlDoc.DocumentByteArray.Length);
     using var sDoc = SpreadsheetDocument.Open(ms, false);
     return(TableNames(sDoc));
 }
 public static XElement RetrieveRange(SmlDocument smlDoc, string sheetName, int leftColumn, int topRow, int rightColumn, int bottomRow)
 {
     using var ms = new MemoryStream();
     ms.Write(smlDoc.DocumentByteArray, 0, smlDoc.DocumentByteArray.Length);
     using var sDoc = SpreadsheetDocument.Open(ms, false);
     return(RetrieveRange(sDoc, sheetName, leftColumn, topRow, rightColumn, bottomRow));
 }
 public static XElement RetrieveRange(SmlDocument smlDoc, string sheetName, string range)
 {
     using var ms = new MemoryStream();
     ms.Write(smlDoc.DocumentByteArray, 0, smlDoc.DocumentByteArray.Length);
     using var sDoc = SpreadsheetDocument.Open(ms, false);
     return(RetrieveRange(sDoc, sheetName, range));
 }
        public static XElement ConvertTableToHtml(SmlDocument smlDoc, SmlToHtmlConverterSettings settings, string tableName)
        {
            using var ms = new MemoryStream();
            ms.Write(smlDoc.DocumentByteArray, 0, smlDoc.DocumentByteArray.Length);
            using var sDoc = SpreadsheetDocument.Open(ms, false);
            var rangeXml = SmlDataRetriever.RetrieveTable(sDoc, tableName);
            var xhtml    = ConvertToHtmlInternal(sDoc, settings, rangeXml);

            return(xhtml);
        }
예제 #5
0
        public static IEnumerable <ValidationErrorInfo> GetOpenXmlValidationErrors(string fileName,
                                                                                   string officeVersion)
        {
            var fileFormatVersion = FileFormatVersions.Office2013;

            try
            {
                fileFormatVersion = (FileFormatVersions)Enum.Parse(fileFormatVersion.GetType(), officeVersion);
            }
            catch (Exception)
            {
                fileFormatVersion = FileFormatVersions.Office2013;
            }

            var fi = new FileInfo(fileName);

            if (Util.IsWordprocessingML(fi.Extension))
            {
                var wml = new WmlDocument(fileName);
                using var streamDoc = new OpenXmlMemoryStreamDocument(wml);
                using var wDoc      = streamDoc.GetWordprocessingDocument();
                var validator = new OpenXmlValidator(fileFormatVersion);
                var errors    = validator.Validate(wDoc);
                return(errors.ToList());
            }
            else if (Util.IsSpreadsheetML(fi.Extension))
            {
                var Sml = new SmlDocument(fileName);
                using var streamDoc = new OpenXmlMemoryStreamDocument(Sml);
                using var wDoc      = streamDoc.GetSpreadsheetDocument();
                var validator = new OpenXmlValidator(fileFormatVersion);
                var errors    = validator.Validate(wDoc);
                return(errors.ToList());
            }
            else if (Util.IsPresentationML(fi.Extension))
            {
                var Pml = new PmlDocument(fileName);
                using var streamDoc = new OpenXmlMemoryStreamDocument(Pml);
                using var wDoc      = streamDoc.GetPresentationDocument();
                var validator = new OpenXmlValidator(fileFormatVersion);
                var errors    = validator.Validate(wDoc);
                return(errors.ToList());
            }
            return(Enumerable.Empty <ValidationErrorInfo>());
        }