General

Components

Community

Development

TDF

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);


Impressum (Legal Info) | Privacy Policy (Datenschutzerklärung) | Statutes (non-binding English translation) - Satzung (binding German version) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Apache License, v2.0. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License v2.0. “LibreOffice” and “The Document Foundation” are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy. LibreOffice was based on OpenOffice.org.