Skip to content

Commit

Permalink
Merge pull request #899 from bcgov/test-rook
Browse files Browse the repository at this point in the history
bug fixes + package-lock fix  to dev
  • Loading branch information
nkan-aot2 authored Mar 20, 2024
2 parents 4118ee2 + 6a13c40 commit 63a6550
Show file tree
Hide file tree
Showing 5 changed files with 1,754 additions and 17,741 deletions.
51 changes: 27 additions & 24 deletions MCS.FOI.S3FileConversion/MCS.FOI.DocToPDF/DocFileProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,36 @@ public DocFileProcessor(Stream SourceStream)
{
SourceStream.Position = 0;

using (var docXML = WordprocessingDocument.Open(SourceStream, false))
if (wordDocument.ActualFormatType == FormatType.Docx)
{

DocumentFormat.OpenXml.Wordprocessing.Body body = docXML.MainDocumentPart.Document.Body;
List<String> originalDates = new List<String>();
foreach (var textItem in body.Descendants<FieldCode>().Where(textItem => textItem.Text.Contains("DATE")))
{
var datetext = textItem.Parent.NextSibling().NextSibling();
originalDates.Add(datetext.InnerText);
}

List<Entity> datefields = wordDocument.FindAllItemsByProperty(EntityType.Field, "FieldType", FieldType.FieldDate.ToString());
if (datefields != null)
using (var docXML = WordprocessingDocument.Open(SourceStream, false))
{
foreach (var (datefield, i) in datefields.Select((datefield, i) => (datefield, i)))

DocumentFormat.OpenXml.Wordprocessing.Body body = docXML.MainDocumentPart.Document.Body;
List<String> originalDates = new List<String>();
foreach (var textItem in body.Descendants<FieldCode>().Where(textItem => textItem.Text.Contains("DATE")))
{
var datetext = textItem.Parent.NextSibling().NextSibling();
originalDates.Add(datetext.InnerText);
}

List<Entity> datefields = wordDocument.FindAllItemsByProperty(EntityType.Field, "FieldType", FieldType.FieldDate.ToString());
if (datefields != null)
{
var dateField = datefield as WField;
//Takes the owner paragraph.
WParagraph ownerPara = dateField.OwnerParagraph;
int dateFieldIndex = ownerPara.ChildEntities.IndexOf(dateField);
//Removes the date field.
ownerPara.ChildEntities.Remove(dateField);
//Creating a new text range with required date.
WTextRange textRange = new WTextRange(ownerPara.Document);
textRange.Text = originalDates[i];//"February 12, 2023";
//Inserting the date field with the created text range.
ownerPara.ChildEntities.Insert(dateFieldIndex, textRange);
foreach (var (datefield, i) in datefields.Select((datefield, i) => (datefield, i)))
{
var dateField = datefield as WField;
//Takes the owner paragraph.
WParagraph ownerPara = dateField.OwnerParagraph;
int dateFieldIndex = ownerPara.ChildEntities.IndexOf(dateField);
//Removes the date field.
ownerPara.ChildEntities.Remove(dateField);
//Creating a new text range with required date.
WTextRange textRange = new WTextRange(ownerPara.Document);
textRange.Text = originalDates[i];//"February 12, 2023";
//Inserting the date field with the created text range.
ownerPara.ChildEntities.Insert(dateFieldIndex, textRange);
}
}
}
}
Expand Down
Loading

0 comments on commit 63a6550

Please sign in to comment.