Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JWord
>
Tutorial
> Remove table row
The example shows you how to remove table's row.
import java.util.List; import com.independentsoft.office.word.WordDocument; import com.independentsoft.office.word.tables.Row; import com.independentsoft.office.word.tables.Table; public class Example { public static void main(String[] args) { try { WordDocument doc = new WordDocument("c:\\test\\input.docx"); List
tables = doc.getTables(); Table table1 = tables.get(0); //first table int rowCount = 0; for (int i = 0; i < table1.getContent().size(); i++) { if (table1.getContent().get(i) instanceof Row) { Row currentRow = (Row)table1.getContent().get(i); rowCount++; if (rowCount == 3) //remove third row { table1.getContent().remove(currentRow); break; } } } doc.save("c:\\test\\output.docx", true); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } }
Need help? Ask our developers:
Name*
Email*
Message*