Skip to content

Conversation

kevlyons
Copy link

@kevlyons kevlyons commented Aug 1, 2019

I needed to have optional cell values and more powerful retrieval instead of immediate child elements.

TableCellContent

tomjebo and others added 3 commits February 4, 2019 22:15
add archive message
point to ericwhitedev/open-xml-powertools
XElement paragraph = tc.Elements(W.p).FirstOrDefault();
XElement cellRun = paragraph.Elements(W.r).FirstOrDefault();
string xPath = paragraph.Value;
bool cellIsOptional = false;

Choose a reason for hiding this comment

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

I believe this could be simplified to:

    var xPath = paragraph.Value;
    var optionalString = "";
    try
    {
        var xElement = XElement.Parse(xPath);
        xPath = (string)xElement.Attribute(PA.Select);
        optionalString = (string)xElement.Attribute(PA.Optional);
    }
    catch { }

    try
    {
        newValue = EvaluateXPathToString(d, xPath, optionalString?.ToLower() == "true");
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants