Inserting image in to the excel cell using jxl api - java

I have to insert image in to the excel cell using jxl api
I have tried with some sample code but it will insert at some coordinator, but I want in to at particular cell index or inside cell.
Here is sample code that I found while searching for this.
Anyone has solution for this?

From a discussion on channel9:
No version of Excel allows you to insert a picture into a cell. Pictures are inserted into the worksheet and will always float.
One of the properties of a picture can be set to "move and size with cells" but that only moves or stretches the picture when the underlying rows and columns are inserted, deleted or sized. It does not confine a picture to a cell.
Here is a step-by-step procedure on how to do it from Excel, maybe you can mime it programmatically.

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.

Moving Sheet order in Excel with apache POI; how to avoid changing formulas

Im trying to move a sheet in my excel between other sheets with Apache POI.
to accomplish that Im calling
workbook.setSheetOrder("sheetToMove", 1);
problem is in another sheet i have formulas like "=sheetToMove!A2"
if I do above call, the formula changes to "=unrelatedSheet!A2"
my current workaround involves going through all cells of the referencing sheet, storing away all the formulas + row/column information in a datastructure before changing sheet orders. after I changed the order, I go thorugh the stored formulas and put them in the correct cell. Is there a more efficient way of changing sheet order without changing the formulas?

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

Open excelfile with an preselected cell

i have an application where i read an excelfile(.xls), make some calculations and present the result. At the result is a button implemented which opens the original excelfile.
Is it possible to provide the specific cell as an arguement to show the cell directly, so that the user does not have to select the cell by himself?
The selected cell is stored within the Excel file. You have to study the API of your Excel writing library to find out, how to set this.
E.g. with POI it would be http://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFSheet.html#setActiveCell(java.lang.String)
Like Holger and Moritz said in their comments, it seems that that it is not possible to startup excel with a given cell preselected.

Categories

Resources