Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropdown support #1243

Open
1 of 5 tasks
nightblade9 opened this issue Dec 21, 2023 · 0 comments
Open
1 of 5 tasks

Dropdown support #1243

nightblade9 opened this issue Dec 21, 2023 · 0 comments

Comments

@nightblade9
Copy link

nightblade9 commented Dec 21, 2023

NPOI Version Used

2.6.2

File Type

  • XLSX
  • XLS
  • DOCX
  • XLSM
  • OTHER

Use Case

My .docx file has a drop-down field that other users fill in, then send back to me for parsing. The dropdown is in a table. I would like to be able to extract the drop-down field.

Currently, I can iterate to the table tag and get the paragraph, but it's empty.

Description

In the underlying docx XML, the list is a ddList and it has a result value, which is an index into the list. There's a good example here of the specification and how to check the value.

Sample Code

Here's how much work it takes to get this value right now:

var table = ...
var answersRow = table.getRow(1); // or whichever row
var cellWithDropDown = answersRow.GetCell(3); // or whichever cell has the dropdown

// Parse the value!
var tc = cellWithDropDown.getCTTc90;
var p = tc.Items.toArray().Single(t => t is CT_P) as CT_P;
var r = p.Items.ToArray().Where(t => t is CT_R).Select(t => t as CT_R);
r = r.Where(r2 => r2.items.ToArray().Any(t => t is CT_FldChar));
List<CT_FldChar> fldChars = new();
foreach (var r3 in r) {
  fldChars.AddRange(r.Items.ToArray().Where(t => t is CT_FldChar).Select(t => t as CT_FldChar));
}
var ffData = fldChars.Single(t => t.ffData != null).ffData;
var ddl = ffData.Items.Single(t => t is CT_FFDDList) as CT_FFDDList;
var index = int.Parse(ddl.result.val);
var value = ddl.listEntry[index].val;
// value now has the string value from the dropdown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants