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 Jan 26, 2022 5:55 pm

hi!

when I generate table with my algorithm it always generate last empty row like this:


is there a way to remove the last row of a table without change my algorithm ?


anyways here is my code that works very well for my generating table:

Code: Select all
            Table table = section.addTable(getBorderCheckBox());
            table.resetCells(((carNumbers.size() + 1) / 5) + 1 , 5);


            //determine how many cell in table and add car numbers into them
            int col = 0;
            for(int r = 0; r < ((carNumbers.size() + 1) / 5) + 1; r++){
                TableRow row = table.getRows().get(r);
                for (int c = 0; c <= 4; c++){
                    Paragraph p = row.getCells().get(c).addParagraph();
                    if(col == carNumbers.size())
                        break;
                    p.appendText(carNumbers.get(col));
                    p.applyStyle("tableStyle");
                    col++;
                }
            }




thanks for helping!
Last edited by wedew222 on Thu Jan 27, 2022 4:43 pm, edited 1 time in total.

wedew222
 
Posts: 8
Joined: Mon Jan 17, 2022 4:01 pm

Thu Jan 27, 2022 6:07 am

Hello,

Thank you for your inquiry.
Please use the following code to delete the last row of the table. If there is any question, please feel free to write back.
Code: Select all
...
// Delete the last row
table.getRows().removeAt((carNumbers.size() + 1) / 5);
document.saveToFile(outputFile,FileFormat.Docx);

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1647
Joined: Wed Apr 07, 2021 2:50 am

Thu Jan 27, 2022 9:49 am

Thank you very much!!

How do i change the position of the table?

If i want it to be under specific text/ line that already written in the doc file that i am loading
or to be at the Middle of the page?

Thanks for helping!!

wedew222
 
Posts: 8
Joined: Mon Jan 17, 2022 4:01 pm

Thu Jan 27, 2022 4:11 pm

wedew222 wrote:Thank you very much!!

How do i change the position of the table?

If i want it to be under specific text/ line that already written in the doc file that i am loading
or to be at the Middle of the page?

Thanks for helping!!



i use the code you wrote here:
how-to-insert-table-into-fixed-position-t6882.html

to insert table in the position of a bookmark and it worked perfectly!!!!!

thank you!!!! :D :D :D :D

wedew222
 
Posts: 8
Joined: Mon Jan 17, 2022 4:01 pm

Fri Jan 28, 2022 1:03 am

Hello,

You are welcome.

If you encounter other issues related to our products in the future, please feel free to contact us.

Have a nice day!

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1647
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Doc