JXLS - add formula for blank cells, formula just disappears - java

I created a report with JXLS and an excel template. I have a bunch of cells/columns pulling data from my database, then I have a few columns that are blank, and then I have some formulas/conditionals in a few columns in my report as well. The issue I am having is that one of the formulas, needs to run/ multiply two blank columns (someone will download the report and input the numbers manually in those blank columns), and when I run the generate the report through my Java app, the column with the formula comes up as =0. Anyways to get the formula to stick, so the people manually entering the numbers in the blank columns do not have to add/input the formula themselves?

You should get Jxls to process AC and AD cells by putting a dummy JEXL expression in there.
The simplest way is to put ${null} into AC and AD cells in your template.

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.

Write with Java Apache Excel file with item and text component as cell values

I worte a code, that generated an output, where other people should choose an acknowledgment value 0,1 or 2. But some people ignored the "value rules" and they wrote other things into the cells. Now I want to generate the output with radio buttons and a textfield for comments. It should not be possible anymore to write other things into the ACKValue cells.
Is this possible to code with Java Apache? Can somebody give me some keyword how to do it. At the end it should be possible to read in the file again and sort the rows with respect to the chosen value.

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

Petaho kettle Java expression to split cell and duplicate value in excel horizontally

I am using Kettle for data migration for moving data, I come across a scenario where i got a excel where the column header is merged, When i read it only the first cell gets the name others are empty, Kettle can only duplicate values vertically, I have a macro which does the exact same thing, But some one has to do it manually, Is there a java code i could run to achieve this?
What do you mean by merged? In the excel file is there one cell with all the values? Is there a separator? If it's not a great deal of columns I'd just manually add them or change them to what I want using a select step. If you'd like to upload files I'll take a look.
I think, got the solution. Here Java code is not required. Please follow the step to achieve your result.
Step1: Drag and drop Microsoft Excel Input to the canvas.And go to Content uncheck Header.
Step2: Go to !Fields tab. See the below image and fill up like below image.
Step3:Go to Additional output fields tab and then check for sheet row nr field and fill up the check box with row_number.
Step4:Finally, click on preview button. You get the result like below.
If you see the result. First three rows are unnecessary. You can filter those three rows by using Filter step this part I'am not done.

Generating a new Excel while retaining old formula from template Excel file

I have an Excel template with first 5 columns left blank (to be populated from an XML). The sixth column has a drop-down list such that depending on whatever value is selected from the list, a value appears in 7th column. This is done by using INDEX-MATCH formula for the 7th column.
=INDEX(Sheet7!$B$1:$B$312,MATCH(F3,Sheet7!$A$1:$A$312,0))
The task is to take this template Excel, and using POI, populate the first 5 columns and generate a new Excel workbook. (Not changing in the existing sheet).
The problem is when I generate the new Excel workbook, the formula isn't copied over from the template. It is really important to retain the formula for the task I am working on. I read about
formulaEvaluator()
but I don't think it'll work in that case because I need the formula to be retained as it is. I cannot evaluate it before copying as there won't be any data in column 6 at that point to evaluate the formula and store the value.
I'd really appreciate if someone who has any experience in this area could guide me a bit.
If you have access to the Cell, simply call:
String formula = cell.getCellFormula();
Note though that this will only work if the cell is formula cell. IE: cell.getCellType() == Cell.CELL_TYPE_FORMULA. If the cell is not a formula cell, you're going to end up with an IllegalStateException as described in the API

Categories

Resources