static void Main(string[] args) { DirectoryInfo di = new DirectoryInfo("../../"); foreach (var file in di.GetFiles("*out.docx")) { file.Delete(); } foreach (var file in di.GetFiles("*.docx")) { Console.WriteLine(file.Name); var newFile = new FileInfo("../../" + file.Name.Replace(".docx", "out.docx")); File.Copy(file.FullName, newFile.FullName); using (WordprocessingDocument wDoc = WordprocessingDocument.Open(newFile.FullName, true)) { FormattingAssemblerSettings settings = new FormattingAssemblerSettings() { ClearStyles = true, RemoveStyleNamesFromParagraphAndRunProperties = true, CreateHtmlConverterAnnotationAttributes = true, OrderElementsPerStandard = true, RestrictToSupportedLanguages = true, RestrictToSupportedNumberingFormats = true, }; FormattingAssembler.AssembleFormatting(wDoc, settings); } } }
private static void Main() { DateTime n = DateTime.Now; var tempDi = new DirectoryInfo( $"ExampleOutput-{n.Year - 2000:00}-{n.Month:00}-{n.Day:00}-{n.Hour:00}{n.Minute:00}{n.Second:00}"); tempDi.Create(); var di = new DirectoryInfo("../../../"); foreach (FileInfo file in di.GetFiles("*.docx")) { Console.WriteLine(file.Name); var newFile = new FileInfo(Path.Combine(tempDi.FullName, file.Name.Replace(".docx", "out.docx"))); File.Copy(file.FullName, newFile.FullName); using (WordprocessingDocument wDoc = WordprocessingDocument.Open(newFile.FullName, true)) { var settings = new FormattingAssemblerSettings { ClearStyles = true, RemoveStyleNamesFromParagraphAndRunProperties = true, CreateHtmlConverterAnnotationAttributes = true, OrderElementsPerStandard = true, RestrictToSupportedLanguages = true, RestrictToSupportedNumberingFormats = true }; FormattingAssembler.AssembleFormatting(wDoc, settings); } } }
public void FA001_DocumentsWithRevTracking(string testId, string src) { /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Load the source document DirectoryInfo sourceDir = new DirectoryInfo("../../../../TestFiles/"); FileInfo sourceDocxFi = new FileInfo(Path.Combine(sourceDir.FullName, src)); WmlDocument wmlSourceDocument = new WmlDocument(sourceDocxFi.FullName); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Create the dir for the test var rootTempDir = TestUtil.TempDir; var thisTestTempDir = new DirectoryInfo(Path.Combine(rootTempDir.FullName, testId)); if (thisTestTempDir.Exists) { Assert.True(false, "Duplicate test id: " + testId); } else { thisTestTempDir.Create(); } var tempDirFullName = thisTestTempDir.FullName; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Copy src DOCX to temp directory, for ease of review var sourceDocxCopiedToDestFileName = new FileInfo(Path.Combine(tempDirFullName, sourceDocxFi.Name)); if (!sourceDocxCopiedToDestFileName.Exists) { wmlSourceDocument.SaveAs(sourceDocxCopiedToDestFileName.FullName); } var sourceDocxAcceptedCopiedToDestFileName = new FileInfo(Path.Combine(tempDirFullName, sourceDocxFi.Name.ToLower().Replace(".docx", "-accepted.docx"))); var wmlSourceAccepted = RevisionProcessor.AcceptRevisions(wmlSourceDocument); wmlSourceAccepted.SaveAs(sourceDocxAcceptedCopiedToDestFileName.FullName); var outFi = new FileInfo(Path.Combine(tempDirFullName, "Output.docx")); FormattingAssemblerSettings settings = new FormattingAssemblerSettings(); var assembledWml = FormattingAssembler.AssembleFormatting(wmlSourceDocument, settings); assembledWml.SaveAs(outFi.FullName); var outAcceptedFi = new FileInfo(Path.Combine(tempDirFullName, "Output-accepted.docx")); var assembledAcceptedWml = RevisionProcessor.AcceptRevisions(assembledWml); assembledAcceptedWml.SaveAs(outAcceptedFi.FullName); Validate(outFi); }
public static void CopyFormattingAssembledDocx(FileInfo source, FileInfo dest) { var ba = File.ReadAllBytes(source.FullName); using (MemoryStream ms = new MemoryStream()) { ms.Write(ba, 0, ba.Length); using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(ms, true)) { RevisionAccepter.AcceptRevisions(wordDoc); SimplifyMarkupSettings simplifyMarkupSettings = new SimplifyMarkupSettings { RemoveComments = true, RemoveContentControls = true, RemoveEndAndFootNotes = true, RemoveFieldCodes = false, RemoveLastRenderedPageBreak = true, RemovePermissions = true, RemoveProof = true, RemoveRsidInfo = true, RemoveSmartTags = true, RemoveSoftHyphens = true, RemoveGoBackBookmark = true, ReplaceTabsWithSpaces = false, }; MarkupSimplifier.SimplifyMarkup(wordDoc, simplifyMarkupSettings); FormattingAssemblerSettings formattingAssemblerSettings = new FormattingAssemblerSettings { RemoveStyleNamesFromParagraphAndRunProperties = false, ClearStyles = false, RestrictToSupportedLanguages = false, RestrictToSupportedNumberingFormats = false, CreateHtmlConverterAnnotationAttributes = true, OrderElementsPerStandard = false, ListItemRetrieverSettings = new ListItemRetrieverSettings() { ListItemTextImplementations = ListItemRetrieverSettings.DefaultListItemTextImplementations, }, }; FormattingAssembler.AssembleFormatting(wordDoc, formattingAssemblerSettings); } var newBa = ms.ToArray(); File.WriteAllBytes(dest.FullName, newBa); } }
public void Sample(string fileName) { var file = new FileInfo(Path.Combine("../../../Word/Samples/FormattingAssembler/", fileName)); var newFile = new FileInfo(Path.Combine(TempDir, file.Name.Replace(".docx", "out.docx"))); File.Copy(file.FullName, newFile.FullName, true); using var wDoc = WordprocessingDocument.Open(newFile.FullName, true); var settings = new FormattingAssemblerSettings() { ClearStyles = true, RemoveStyleNamesFromParagraphAndRunProperties = true, CreateHtmlConverterAnnotationAttributes = true, OrderElementsPerStandard = true, RestrictToSupportedLanguages = true, RestrictToSupportedNumberingFormats = true, }; FormattingAssembler.AssembleFormatting(wDoc, settings); }