How to influence where a table cell get's split with iText? - java

I am using iText 2.1.7.
I like to influence where a table cell get's split. So e.g. if the word example-adress#123server.com is in the cell but the width of the cell requires splitting the string in three, then I'd like to tell iText somehow to split it like this "example-", "adress", "123server.com"
How can I do this?

Related

Apache POI (DOCX) XWPFTable asymmetric cell

I want to create a table looks like
this.
but the only way to to this is with an horrible merge of cells.
i try to make two separate table but the top table, follow the cell width of bottom table like this.
There is a way to make an asymmetric table without merge cells?
You don't have to 'merge' cells, but you do have to tell it how many grid columns or rows the cell spans. Picture a grid that has a column that matches every column position, and a row that matches every row position. In your example, you would have a grid with 18 columns and 3 rows. Then for each cell that spans one or more grid column or row, you must have a span attribute that tells how many grid positions are spanned by the cell. The result is the same as merging, and it might even be what you meant by merging, but that is the way the spec reads.

POI JAVA appending cell without affecting cell format

Im trying to append a cell in a sheet, for example the cell 1A has a border and filled with color grey and I want to insert a string "hello", but using
cell.setCellValue("hello");
destroy the cell format or rather make the cell format in default mode. I know how to use the
CellStyle cs = workbook.createCellStyle();
method but in my project I'm inserting many different data with different cell format. I googled it and no luck finding an answer.
Is there another way to solve my problem?
To elaborate my problem.
In my sheet in 1A I have a cell format
Cell format (fill with color grey and have thin border)
but when I use
cell.setCellValue("hello");
it makes the cell's format become default but I want my cell to become like this without using CellStyle cs = workbook.createCellStyle();
cell I want
Is there a way to this?
I believe you have an excel workbook and you wanna append data to it. If you wanna keep the existing format and insert data to it you can do that using below code
cell = sheet.getRow(0).getCell(0);
cell.setCellValue("Hellooooo");
but if you are create a new cell by using
cell = sh.createRow(0).createCell(0);
then you're destroying the current format, in that case you have to create all required cellStyle all over again.

How to reduce line height inside merged cell using Apache POI?

I filled text inside merged cell using Apache POI. I want to reduce line height inside cell because second text line is not visible fully. I search something like CSS style line-height but for excel.

Calculate row height for HSSFRow

I'm writing an Excel (xls) sheet with Apache POI 3.13. I set the column width manually. If the content of a cell is too long, I want it to be wrapped and the column height to be adjusted.
If I set the wrapText property of the CellStyle to true, the text does not "flow" out of the cell any more, but how do I set the height of the row to a fitting value?
All approaches I've seen calculate the newline characters in the string. This is not working for me, since my text does not contain manual newlines.
This seems to be a LibreOffice bug, because with Excel on a Windows system it looks as expected.

Set a specific cell width to column in XSSF Apache POI

I am trying to export a table as xlsx using Apache POI XSSF. Table has 5 columns.
First row has title block merging 5 columns. In the second row, 5 headings for the table. Remaining rows are data. I want to set width of the column as max width of each heading blocks.
I tried mySheet.autoSizeColumn(colnum) and mySheet.setColumnWidth(columnIndex, width). Problem with AutosizeColumn, it is returning the highest width of the data in all the rows. So If width of some data in table is more, table header width is becoming very large.
And for the second one, setColumnWidth, I need to know width of the header cell so I can set it to the sheet. But how to find the width of a specific cell? Had no luck yet in figuring out how to do it. Any idea on how to that?
I would suggest simple solution that I have used.
Use a condition and after writing the 2nd row, i.e. the heading row, use AutosizeColumn() it will change the cell width according to the header width and then the width will remain as it is.

Categories

Resources