-
-
Notifications
You must be signed in to change notification settings - Fork 197
Open
Description
The following code as per ChatGPT fails to correctly highlight differences on word document that was initially uploaded.
private void ApplyDiffToDocument(string filePath, DiffPaneModel diff)
{
using var doc = WordprocessingDocument.Open(filePath, true);
var body = doc.MainDocumentPart.Document.Body;
body.RemoveAllChildren<Paragraph>();
foreach (var line in diff.Lines)
{
var para = new Paragraph();
var run = new Run(new Text(line.Text));
var props = new RunProperties();
Highlight highlight = null;
switch (line.Type)
{
case ChangeType.Inserted:
highlight = new Highlight() { Val = HighlightColorValues.Green }; break;
case ChangeType.Deleted:
highlight = new Highlight() { Val = HighlightColorValues.Yellow }; break;
case ChangeType.Modified:
highlight = new Highlight() { Val = HighlightColorValues.LightGray }; break;
}
if (highlight != null)
props.Append(highlight);
run.RunProperties = props;
para.Append(run);
body.Append(para);
}
doc.MainDocumentPart.Document.Save();
}
Metadata
Metadata
Assignees
Labels
No labels