Skip to content

Fixes #1608, adds support for multiple alternate content sections#1609

Merged
tonyqus merged 1 commit into
nissl-lab:masterfrom
kemsky:alternate_content_1608
Jul 25, 2025
Merged

Fixes #1608, adds support for multiple alternate content sections#1609
tonyqus merged 1 commit into
nissl-lab:masterfrom
kemsky:alternate_content_1608

Conversation

@kemsky
Copy link
Copy Markdown
Contributor

@kemsky kemsky commented Jul 23, 2025

#1608 Tested locally, seems to work.

AlternativeContent sections can also contain paragraphs, this is something that might need attention later.

@tonyqus tonyqus added this to the NPOI 2.7.5 milestone Jul 23, 2025
@tonyqus tonyqus requested a review from Copilot July 23, 2025 10:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for multiple AlternateContent sections within a Word processing run, addressing issue #1608. The change modifies the data structure to handle a collection of alternate content items rather than a single instance.

  • Changes alternateContent field from single object to List collection
  • Updates parsing logic to accumulate multiple AlternateContent sections
  • Modifies serialization to iterate through all alternate content items

Comment thread OpenXmlFormats/Wordprocessing/Run.cs Outdated
Vml.CT_AlternateContent alternateContentField = null;

List<Vml.CT_AlternateContent> alternateContentField;
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternateContentField should be initialized to prevent null reference exceptions. Consider initializing it as 'new List<Vml.CT_AlternateContent>()' or ensure all usage checks for null.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change the name to alternateContentFields?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tonyqus , done.

Comment on lines +617 to +621
if (ctObj.alternateContent == null)
{
ctObj.alternateContent = new List<Vml.CT_AlternateContent>();
}

Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null check and list initialization happens inside the loop for each AlternateContent element. Consider initializing the list once outside the parsing loop or in the constructor to avoid repeated null checks.

Suggested change
if (ctObj.alternateContent == null)
{
ctObj.alternateContent = new List<Vml.CT_AlternateContent>();
}

Copilot uses AI. Check for mistakes.
@kemsky kemsky force-pushed the alternate_content_1608 branch from 3007c94 to 9e0784d Compare July 24, 2025 15:18
@tonyqus
Copy link
Copy Markdown
Member

tonyqus commented Jul 25, 2025

LGTM

@tonyqus tonyqus merged commit 56cb402 into nissl-lab:master Jul 25, 2025
2 of 3 checks passed
@kemsky kemsky deleted the alternate_content_1608 branch July 26, 2025 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants