コード例 #1
0
 public static PmlDocument SearchAndReplace(PmlDocument doc, string search, string replace, bool matchCase)
 {
     using var streamDoc = new OpenXmlMemoryStreamDocument(doc);
     using (var document = streamDoc.GetPresentationDocument())
     {
         SearchAndReplace(document, search, replace, matchCase);
     }
     return(streamDoc.GetModifiedPmlDocument());
 }
コード例 #2
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>());
        }