Splitting a PDFTable cell into two columns using Itext Java - java

I'm trying to draw a table like the one in the image and I can't split a cell into two columns like the last two columns of the table. Please help me with some ideas. I'm using Itext api for creating the PDF file.

Instead of trying to split the Din care column, have that data in two columns (so 4 columns in total for the entire table) and then merge only the top cell by letting it span two columns. You do this with setting setColspan(2) on the Din care cell.
Additionally you may want to look at setRowspan() for the Categoria de Varsta and Total cells.

Related

Shifting rows only in specific columns

I'm trying to shift rows down in my excel sheet and insert new data to the top of the list.
I'm able to shift rows down as:
int row = getItemsListSize(); <- which returns size of the list which contains elements
sheet.shiftRows(1, sheet.getLastRowNum(), rows);
Then I insert new data starting from row 1 and that way newest data is always on top of the list and older data gets moved down.
My problem is that I have second table also on that sheet and amount of items inside it isn't same as in first table. Currently also contents of this table gets moved down although no new items aren't added. Because of that it looks weird.
Is there way to only shift rows inside specific columns? For example: Move rows only in columns A-D.
No; from an excel perspective, there is no such thing as two separate tables. It's just one big sheet with rows and columns. Apache POI is a library that gives you access to excel's data structures. It's not a generalized 'mess with sheets' library. You'd have to write the code for such such a thing yourself.
More generally you're misusing excel a bit. The right move usually is to treat data, as, well, data. You should not be having 2 unrelated tables on the same sheet. Use the + button at the bottom left (or the appropriate POI option, which also supports sheets) to add another sheet.
If you want a sheet for visual reasons, make a third sheet, and that is a sheet that your POI code should never touch - it will render the data from the other (data) sheets. You can now add graphs, logos, whatever you want, and you won't run into issues where moving things around a bit 'because it looks nicer visually' then results in your POI-based code being broken.

How to search and manipulate data on jTable in java in netbeans

[i need help in java programming in netbeans.
suppose i have 2 jTable. the first table contains the imported data from the excel file (I do not use data in the database). And the second table serves to display data calculation results from the first table earlier.
questions asked are:
how to find the value of MAXIMUM and MINIMUM in each column, starting from column two, third and so on. and displayed eg in jTextfiield?
how, for example I have a sum formula, which serves to add all the values ​​in row 1 in columns 2,3,4, and so on in the first table. then the formula will be reused on the second line, then and so on for each row in the first table, according to the number of rows in the first table. such as in excel, (which when we have a certain formula we live just copy and drag the cursor down, then automatically all the values ​​on all rows summed)?
lastly how to display all the data in the first table along with the result of the sum in each line before the previous formula, in the second jTable?
please help, just info I use java in netbeans. and for the image of his table I attach also along with this post. thanks.]1

Java TableItem, TableEditor, texts and buttons - all dynamically created

I want to create a table (that will finally exist in a new eclipse view). This table has a few text columns, and a column that has a different behavior based on the other columns. It can either be a field to enter text, or to popup a dialog for users to select data from (and it has to be a popup or a dynamically created combo). Anyway, I know which of the two I need for each row in the column.
My table is built using TableViewer and a few TableViewerColumn's in it. I later fill them with String data in TableItem's up to 4 columns. The fifth is the one I have this special behavior.
I tried experimenting with TableEditor, but failed:
When I used one for each TableItem it somehow got misaligned with the table rows and columns
When I use one for the entire table, I fail to set a Text entry on specific rows
What I need help with is figuring out exactly how to achieve this:
A Table that has 4 String columns, where the data is constant (cannot be changed by the user)
A fifth column where the cell contents is either a Text for the user to enter, or a (preferably transparent) Button that has a popup as action, or a Combo that I dynamically fill with data upon table creation
Any idea would be highly appreciated.
OK, got this figured out. The example here helped a lot:
http://www.java2s.com/Tutorial/Java/0280__SWT/TableCellEditorComboTextandButton.htm
Oren

How to make table with multiple lines per row?

I'm trying to find a way to make a Java table (Swing component) that can wrap the list of columns into multiple lines per row.
/[ Column Hdr A ][ Column Hdr B ]
Hdr |[ Column Hdr C ][columnHdr D ][ColumnHdr E ]
\[ column Hdr F ][COlhdr G][colhdr H][CH I]
/[ Cell 1 A ][ Cell 1 B ]
Row 1|[ Cell 1 C ][cell 1 D ][Cell 1 E ]
\[ Cell 1 F ][Cell 1 G][Cell 1 H][C 1I]
...
Where each column size is independent of any other. IE: I'm not doing spanning or column header grouping. It should retain the column resizing, hiding and sorting features. Drag and drop re-ordering would be nice but isn't necessary.
So I've searched everywhere for something like this. All I've found are various schemes for spanning cells or using fixed width sub-columns. There was one person who claimed to have done it by overriding getRect, but there was no code to look at, so I'm not sure how that would work wrt to resizing or hiding columns, and how would you specify which columns went where?
I've considered just extending TableColumn to include a "sub-row" property but that means also having custom TableColumnModel, JTableHeader and Jtable, AND Jpanel. And I suspect that the renderer and all the LookandFeel UIs would also have to be modified.
An ugly hack that occurred to me is to create one table per sub-row of columns, and then use some form of mutant jpanel to expose the rendered rows interleaved down the y axis. I'm not sure that would work with scroll bars though.
So, does anyone have a neat, concise way to implement this? Any suggestions about how to proceed?
I would hope that you would re-organize the output to be more human readable. While this does fit the data onto the page, a human reading it would have a great deal of problems trying to understand what table cell belonged to what header and which row was which.
Can you create rows with only the 'important' data visible first, then the user could click (or some gesture) to open the more detailed results? Or include multiple cell values together in a multi-line cell to reduce the data to a single row per record?
This gives you two great benefits. First the data will be understandable at a glance, and second, you can use the existing table implementations and save yourself the significant development work.
Finally, have you tried using an HTML widget to display the data? You could create the table as divs in HTML and have the widget wrap the rows. Then you could style the cells for each column to be a fixed width.
I can't offer you any code, but you could look into customizing the table model (class MyTableModel extends AbstractTableModel {...}).
The approach could be to overload the SetValueAt(Object value, int row, int col) method so that writing row 1, col 3 for example would actually write row 2 , col 1 and so on to display multiple lines for 1 line of you data table
Do you indeed need the behaviour which prevents some columns from scrolling?
It is a quite standard usability solution. I would recommend you to come up with a dialog allowing to hide and freeze columns. In this case users could organize the viewport the way they feel best at the moment. Here is an example of scroll freezing.
The second option may well be HTML. You can generate whatever you want this way. Though this solution may have a limitation if you need to edit your data.
Ergonomics uggestions:
Is it acceptable to present headers or data vertically? Sometimes it is better readable.
Basically JTable supports adding swing components including nested tables or cells. please refer to the ff links
com.lang.java.gui discussion
a similar thread

Adding Table In Cell of Another Table in docx file using POI

I am using POI to generate a docx file. I need to create table in which a cell of table contains another table. How this can be done?
I had the same problem.
Instead of insert a table into a tableCell, I decided to "split" the cell, although I was not able to do it.
So, I decided to create new rows/column and merge all cells except the cells at the row/column I wanted to split.
For merging the cells I decided to follow the following steps:
For merging horizontally/vertically you need to create 2 CTHMerge and use the setVal:
one for the cells that you will remain (STMerge.RESTART);
a second one for the merged cells (STMerge.CONTINUE);
a) example for a horizontal merge for 2x2 table:
// First Row
CTHMerge hMerge = CTHMerge.Factory.newInstance();
vmerge.setVal(STMerge.RESTART);
table.getRow(0).getCell(0).getCTTc().getTcPr().setHMerge(hMerge);
table.getRow(1).getCell(0).getCTTc().getTcPr().setHMerge(hMerge);
// Secound Row cell will be merged/"deleted"
CTHMerge hMerge1 = CTHMerge.Factory.newInstance();
hMerge.setVal(STMerge.CONTINUE);
table.getRow(0).getCell(1).getCTTc().getTcPr().setHMerge(hMerge1);
table.getRow(1).getCell(1).getCTTc().getTcPr().setHMerge(hMerge1);
b) example of a vertical merge (image with example)
// First Row
CTVMerge vmerge = CTVMerge.Factory.newInstance();
vmerge.setVal(STMerge.RESTART);
table.getRow(0).getCell(0).getCTTc().getTcPr().setVMerge(vmerge);
table.getRow(0).getCell(1).getCTTc().getTcPr().setVMerge(vmerge);
// Secound Row cell will be merged
CTVMerge vmerge1 = CTVMerge.Factory.newInstance();
vmerge.setVal(STMerge.CONTINUE);
table.getRow(1).getCell(0).getCTTc().getTcPr().setVMerge(vmerge1);
table.getRow(1).getCell(1).getCTTc().getTcPr().setVMerge(vmerge1);

Categories

Resources