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

'OpenXmlElementList' does not contain a definition for 'GetItem' #1651

Open
Aurimelis opened this issue Jan 19, 2024 · 15 comments
Open

'OpenXmlElementList' does not contain a definition for 'GetItem' #1651

Aurimelis opened this issue Jan 19, 2024 · 15 comments
Assignees

Comments

@Aurimelis
Copy link

Missing method for getting item from OpenXmlElementList class.

Starting from version: 3.0.0

Working version: 2.20.0

Error CS1061 'OpenXmlElementList' does not contain a definition for 'GetItem' and no accessible extension method 'GetItem' accepting a first argument of type 'OpenXmlElementList' could be found (are you missing a using directive or an assembly reference?)

@twsouthwick
Copy link
Member

Can you share your code sample?

Did you try:

OpenXmlElementList list = ....;
var item = list[index];

There were a number of breaking changes from v2.x - not sure if this one got documented, but let me know if it works and I'll make sure the docs are updated.

@Aurimelis
Copy link
Author

Tried, seems to work. I was just not finding any breaking change in the docs regarding that method.

@AlfredHellstern
Copy link
Collaborator

@twsouthwick what exactly is needed here? Code change or documentation?

@twsouthwick
Copy link
Member

Docs update

@Babufrik123
Copy link

Docs update

How to do that??

@Babufrik123
Copy link

Can you share your code sample?

Did you try:

OpenXmlElementList list = ....;
var item = list[index];

There were a number of breaking changes from v2.x - not sure if this one got documented, but let me know if it works and I'll make sure the docs are updated.

Where to write this??

@twsouthwick
Copy link
Member

@Babufrik123

https://github.com/OfficeDev/open-xml-docs/blob/main/docs/migration/migrate-v2-to-v3.md

Happy to take a PR to update that or any other doc changes :)

@Babufrik123
Copy link

@Babufrik123

https://github.com/OfficeDev/open-xml-docs/blob/main/docs/migration/migrate-v2-to-v3.md

Happy to take a PR to update that or any other doc changes :)

Can u please explain in detail what exactly nedds to be done to use getitem().

@twsouthwick
Copy link
Member

OpenXmlElementList list = ....;
var item = list.GetItem(index);

to

OpenXmlElementList list = ....;
var item = list[index];

@Babufrik123
Copy link

OpenXmlElementList list = ....;
var item = list.GetItem(index);

to

OpenXmlElementList list = ....;
var item = list[index];
OpenXmlElementList list = ....;
var item = list.GetItem(index);

to

OpenXmlElementList list = ....;
var item = list[index];

Hi twsouthwick,
I still didnt unterstand, can u please give a step by step guide. Actually I m reading data from excel to data table using document open xml and there that getitem() is required.But due to latest version I m not able to use that.I m attaching the link of my code please refer that and share what to do.

https://www.aspsnippets.com/Articles/1463/Read-and-Import-Excel-data-to-DataTable-using-OpenXml-in-ASPNet-with-C-and-VBNet/

@twsouthwick
Copy link
Member

What I supplied is the only step needed. The call to GetItem needs to be changed to an indexer.

@Babufrik123
Copy link

What I supplied is the only step needed. The call to GetItem needs to be changed to an indexer.

doc.WorkbookPart.SharedStringTablePart.SharedStringTable.ChildElements.GetItem(int.Parse(value)).InnerText

How will you rewrite this?

@Babufrik123
Copy link

What I supplied is the only step needed. The call to GetItem needs to be changed to an indexer.

doc.WorkbookPart.SharedStringTablePart.SharedStringTable.ChildElements.GetItem(int.Parse(value)).InnerText

Help me rewrite this. U can see getitem here

@BazInTheAZ
Copy link

BazInTheAZ commented Mar 7, 2024

What I supplied is the only step needed. The call to GetItem needs to be changed to an indexer.

doc.WorkbookPart.SharedStringTablePart.SharedStringTable.ChildElements.GetItem(int.Parse(value)).InnerText

Help me rewrite this. U can see getitem here

doc.WorkbookPart.SharedStringTablePart.SharedStringTable.ChildElements[int.Parse(value)].InnerText

@twsouthwick
Copy link
Member

Thanks @BazInTheAZ :) @Babufrik123 I'd recommend taking a look at some of C# specifications so you can understand the syntax here: https://learn.microsoft.com/dotnet/csharp/programming-guide/indexers

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

6 participants