Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Aug 09, 2023 4:59 am

i am currently using the spire.doc free version 5.2.0. i encounter the following issue when i am trying to remove cell every row. I also reference the .NET/C# operation here posted in e-iceblue tutorial site.

The error shown is the following.
java.lang.IndexOutOfBoundsException: Index: 42, Size: 42
at java.util.ArrayList.rangeCheck(ArrayList.java:659)
at java.util.ArrayList.get(ArrayList.java:435)
at com.spire.doc.packages.sprlez.spr⇆╻(Unknown Source)
at com.spire.doc.collections.BookmarkCollection.get(Unknown Source)
at com.spire.doc.collections.CellCollection.spr┈┃—(Unknown Source)
at com.spire.doc.collections.CellCollection.removeAt(Unknown Source)


Below is the code I use to perform the cell deletion
Code: Select all
Table table = this.getTableFromDocumentByName(tableName); // this line will get the table by table title
        if(table != null) {
            for(Object obj : table.getRows()) {
                TableRow row = (TableRow) obj;
                log.debug("count :: {}, index :: {}", row.getCells().getCount(), index);
                row.getCells().removeAt(0);
            }
        }

alloy628
 
Posts: 1
Joined: Wed Aug 09, 2023 4:25 am

Wed Aug 09, 2023 9:41 am

Hello,

Thank you for your inquiry.
Based on the error information and code you provided, we speculate that the size of the cells in your file is 42, but your index is also 42, which is why IndexOutOfBoundsException appears. Please set your "index" value to "row.getCells().getCount()-1" before testing. If there are still issues with the test results, to help us investigate further, please provide the following information for our reference. You could attach them here or send them to us via email ([email protected]). Thanks in advance.
1) Your Word file and complete executable code.
2) Your JDK Version such as JDK1.8.

Sincerely,
Wenly
E-iceblue support team
User avatar

Wenly.Zhang
 
Posts: 149
Joined: Tue May 16, 2023 2:19 am

Return to Spire.Doc