Enable sorting in protect Sheet Apache POI - java

After protected the sheet.
sheet.protectSheet("");
Not able to enable sorting.
The new version of POI. Not have an argument to enable the sortingin a protected sheet. It has only to disable sorting.
sheet.lockSort();
I tried this also.
CTSheetProtection sheetProtection = excelSheet.getCTWorksheet().getSheetProtection();
sheetProtection.setSort(false);
But this function enables the sorting button in excel sheet. But after I click the A-Z or Z-A I am getting the pop-up. Because of the sheet protection.
I am using this <version>3.10.1</version>.
I am using a protection method for the user do not edit some column in sheet.
But I need sorting in a protected sheet.
One more question also.
Is this possible to lock the first row of excel. Because do not sort the title row.
But I used
sheet.createFreezePane(0, 1);
This will freeze from scrolling, not from the sorting. Please help with these two questions.

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?

Applying Excel sheet drop down list validations using Java (Apache poi API)?

I've done coding for Excel sheet drop down list for a specific column but I want to apply validation.
For example - once the any value of drop down was selected in first row it'll not display in the second row.
How can I achieve this?

Issue during Grouping and Ungrouping using Apache POI and java

I am able to write to excel Sheet by Using Apache POI with Java.
Also, I am able to groupby Row, as mentioned in the requirement.
But, the issue which I am facing is:
I create multiple sheets in the workbook, and use "groupRow" to group data in the sheets.
And, I need to activate the 2nd sheet, by default. All, works fine, apart from the expand(+) button to "Ungroup" the "group".
Basically, when I open the excel, the 2nd sheet is selected by default and the similiar data are grouped also. But, when I click the "Ungroup" button(+), It does not work.
Note: If I navigate to some other sheet and come back to the same sheet, then the "Ungroup" button works fine.
Its due to the fact that the "Data Tab" is deactivated by default.
How do I activate the "Data Tab" by default, so that the "Ungroup" button works fine.
So, Basically, I need the "Ungroup" button to work ,without navigating to some other sheet.
Appreciate your help and Support.
If possible please share code snippet.
Below are the code Snippets:
sheetx = wb.createSheet();
sheetx.groupRow(4, 11);
sheetx.setRowGroupCollapsed(4, true);
wb.setActiveSheet(1);

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