ODFDOM Java Interface simple array to table example

735 views Asked by At

I am looking for how to handle the different ODFDOM classes, I can not find out looking at the documentation online how to solve this:

  1. I got an ArrayList , which I want to list in different tables. There should be at the end 3 different tables on each page, i.e. if in the ArrayList are stored about 20 Persons, it should be about 7 pages, each page containing 3 tables.

  2. I wrote a small class, which can print out the tables, and the arraylist, but I still miss the following three points.

    a. how is the fix definition of a row/cell hight? Or the overall hight of one table? I want to have a fixed height, the text in one cell can be wrapped, but the wrapping should not be covering more than four lines. If I have 5 rows, the overall height of a table should stay the same.

    b. how can I define the properties for a cell, i.e. the font size, kind, color etc. Also how can I define the border for the table, or the cells?

    c. To get 3 tables exactly with data and same height, how do I tell the program that it should include a page or paragraph break after said 3 tables.

Here is the class

import java.util.List;
import static org.odftoolkit.odfdom.dom.style.OdfStyleFamily.Table;
import org.odftoolkit.simple.TextDocument;
import org.odftoolkit.simple.table.Cell;
import org.odftoolkit.simple.table.Row;
import org.odftoolkit.simple.table.Table;

public class Test
{
    public void doIt(TextDocument document, Person person, int y)
    {

        try
        {
            int row = 6;
            int column = 2;

            Table table = Table.newTable(document, row, column);
            table.setTableName("BigFive" + y);

            if (table != null)
            {
                long width = 170;
                table.setWidth(width);
                table.setVerticalMargin(0.1, 0.1);
            }

            List<Row> rows = table.getRowList();
            for (int x = 1; x < rows.size(); x++)
            {
                rows.get(x).setHeight(22f, true);
            }

            for (int i = 0; i < rows.size(); i++)
            {

                Cell cell = table.getCellByPosition(0, i);

                if (i == 0)
                {
                    cell.setStringValue(person.getItem(i));
                }
                else
                {
                    cell.setTextWrapped(true);
                    cell.setStringValue(person.getItem(i));
                }

            }
        }
        catch (Exception e)
        {
            System.out.println("Error in " + e);
        }
    }
}
0

There are 0 answers