General

Components

Community

Development

PPMC

ASF

Documents > Cookbook >Column and Row



Get Column/Row
The class Column/Row represents the column/row of table.To get all the columns or rows you can use the getColumnList or getRowList of the table instance.

    List<Column> columns = table.getColumnList();
List<Row> rows = table.getRowList();

You can also get single column/row by specifying the index of the column/row.
The column/row index start from 0.If not found, null will be returned.

    
Column column = table.getColumnByIndex(2);
Row row = table.getRowByIndex(0);

If you want to know the count of header column/row in the table,you can do like this:

    int headerColumnCount = table.getHeaderColumnCount();
int headerRowCount = table.getHeaderRowCount();

If you want to know the index of the column/row,you can use the method below:

    int columnIndex=column.getColumnIndex();
int rowIndex=row.getRowIndex();

Can I get the previous or next Column/Row by the current column/row instance?
Yes,you can ask the column/row instance itself,if it doesn't exist,null will be returned.

    Column previousCol=column.getPreviousColumn();
Column nextCol=column.getNextColumn();
Row previousRow=row.getPreviousRow();
Row nextRow=row.getNextRow();


Append or Insert Column/Row
You can add a column to the end or insert many columns before the specified index
The appendColumn/Row method add an empty column/row at the end and return the new appended column/row

    Column newColumn=table.appendColumn();
Row newRow=table.appendRow();

What can I do if I want to insert a column/row into the specified position?
You can use the insertColumn/RowBefore method,whose first parameter is the index of the column/row to be inserted before; The second parameter is the number of columns/rows to be inserted.

    List<Column> cols = table.insertColumnsBefore(1, 2);
List<Row> newRows = table.insertRowsBefore(0, 2);


Remove Columns/Rows
You can delete a number of columns/rows by index
The first parameter is the index of the first column/row to delete; The second parameter is the number of columns/rows to delete.
The code below remove 1 column whose index is 2;remove 2 rows whose index is 1,2.

    table.removeColumnsByIndex(2, 1);
table.removeRowsByIndex(1, 2);


Set Column/Row
If you want to change the width of the column or the height of the row,you can use it like this:
If the second parameter of row's setHeight is true, the row can fit the height to the text, vice versa.

    column.setWidth(column.getWidth()/2);
row.setHeight(row.getHeight()/2, true);



Powered by the Apache CMS.

Apache "ODF Toolkit" is an effort undergoing incubation at The Apache Software Foundation (ASF), sponsored by the Apache Incubator. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.

Copyright © 2011 The Apache Software Foundation Licensed under the Apache License, Version 2.0. Contact Us
Apache and the Apache feather logos are trademarks of The Apache Software Foundation.
Other names appearing on the site may be trademarks of their respective owners.