Apache Poi formula Strings - java

I have a strange behavious and hope that someone might know what is going on.
For a personal project in Java i'm using Apache poi (version 3.9) to read and write to excel files.
In these excel files there is a formula i wanted to change to another way writing it.
I have a loop that sets my Excelobject with the required formula string
excelobject.setDataFormula("SUM(L" + counter + "-6,75)"); // it will look like SUM(L2-6,75) and so on
However when i write these formula in a file and check it. it has mysteriously changed to something like SUM(L2-6;75). changing the , to a ; and thus the formula does not work like intended.
can someone explain to me why apache poi setFormula on a cell does this to a , ?
EDIT :
I changed my loop to use a double 6,75 instead of a string 6,75 and that seems to help when creating the formula. So this immediate question is fixed though I am still curious on why this behavious comes.

Go to Control panel -> Region and Language -> Additional settings and change the List Separator to something other than a comma. You should use a character that doesn't appear in your file. Be sure to pick something that won't be added to the file in future either.
It changes from , to ; because , is being used as a delimiter. Anywhere that a , is found indicates a new cell. When your string is read, it changes the comma so that 2 cells wont be created where there should only be one. If you change the List Separator as described, the comma should remain unchanged.

Related

Eclipse doesn't split string at line width when formatting

I'm currently working on an application in Eclipse where I'm running a really huge SQL statement that spans about 20 lines when splitting it in notepad to fit on the screen. Thus I want the string for the query also to be formatted somewhat more readable than a single line. All the time autoformatting normally worked when I used Eclipse but somehow now neither Ctrl + Alt + F nor rightclicking and selecting the "Format" option from the menu doesn't work to get a line break after a certain amount of characters.
I already checked the preferences where I already tried running my own profile with 120 and 100 characters line width but that didn't fix anything so far. I really don't know why Eclipse won't let me format this anymore. Normally Eclipse would be splitting the string into several lines in this case but I don't really know why this doesn't work anymore.
However other formatting is being fixed when executing autoformatting (e.g. if(xyz){ still becomes if (xyz) {.
Thank you for your help in advance.
As far as I can tell, autoformat as you described was never supported (at least as far back as 2008). And I have been using Eclipse much longer than that
You can do one of several things.
Simply insert the cursor in the string and hit a return.
Toggle word wrap Alt-Shift-Y
Try writing a regex to do what you want(not certain if this will work).

JAsper Report 3.0 issue :

I am using jasper Reoprt Ireport 3.0 for Generating excel. my problem is I have One text field in that i want to keep below data which is coming from my database.
**Disclaimer: Please note that in case of disease conditions which can have both Acute and Chronic manifestations, they are considered as Chronic illness for analysis keeping in view the objective of the report.
Actually in jasper reoprt summary area i have given one text field but it is too small too keep this above line data. but still I want to keep whole data in small field in excel .
because normaly when we are typing in excel cell anything and when it become overflows then also it's looking like it has been typed in next cell but ,when we are clicking in another cell it will show in that cell only.whole data will come in that small cell without wrapping text filed.
just like it i want also through I-report 3.0 . I tried so much but I didn't find solution so i am posting here . please suggest if you faced same problem and got solution too. it will be helpful.
I don't want to merge it in multiple columns because if it will merge multiple columns then for calculating value through Excel column selection will be a problem. and V lookup we cant do so.
if the data in any cell is greater than 2 rows, then the remaining data just gets cut off and not displayed.
Maybe it is time to update. At this time JasperReports 6.x is the version to go, but ...
From my expierience JasperReports is the wrong tool to generate "clean" Excel documents. You get always layout informations in it that result in the behaviour you describe.
To get a clean Excel document I would suggest to go with Apache-Poi (https://poi.apache.org/) and generate it directly or simply to generate a CSV - file which can be easily opened using Excel.

Java, Apache POI, cell value won't change when seen from MS Excel

I'm using Apache POI to modify an existing Excel file (something.xls).
After I set a cell value using:
sheet.getRow(3).getCell(30).setCellValue(222);
I can see the changes reading the value from the same cell with:
sheet.getRow(3).getCell(30).toString();
BUT when I'm opening the something.xls file with MS Excel the change is gone.
Now the funny part:
-If I'm rerunning the code without the line where I set the cell value, I can still see 222, so the change is there, only I see the
old value from MS Excel for some reason.
-I triple checked to make sure I'm not editing a different file from code and opening another with Excel.
-I tried changing some other random cells in a similar way and some work, while others do not. (the cells do not contain formulas and all
are numeric type)
I would really appreciate if anyone could offer an explanation and solution.
Thanks in advance.
I copied the contents of the existing excel file (manually, without any formatting) to a new one and formatted it again. It is working now. I must have set something wrong the first time, I couldn't figure out what though. Thanks for the replies.

How can I output id number in excel without error warning

I am using POI to output a product id into excel cell. The product id is a numeric string like
"0000001", "3212230".
After the excel is generated, I found the cell holds this id value has an error check warning "The number in this cell is formated as text or preceded by an apostrophe". If I double click on this cell in excel, it will automatically correct "0000001" to 1, which is not what I want. I know I can turn the error checking option off in excel manually, but that's not what I want.
Is there anyway to keep excel quiet and considering this id as a text?
Here is the code snippet:
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(new HSSFRichTextString( quote.getQuoteId() ));
cell.setCellStyle(styles.get("table_t"));
It seems this is not supported yet by POI. However, the low level implementation seems to be done as part of bug 46136. This bug is waiting for suggestions for specifying an interface for this feature so I'd say the best to get this done one day would be to contribute your remarks and maybe vote for it. I just voted right now.
Can you precede it with a single quote?
cell.setCellValue(new HSSFRichTextString("'" & quote.getQuoteId() ));
Not really. Excel really loves its numbers which is why that is considered an error. About the only thing that would make Excel happy would be to change your QuoteId format to start with a letter instead of being completely numeric.

How to avoid pdfbox appending separate words

I'm making an application which allows searching in pdf's using apache Solr. I was having trouble finding certain terms in pdfs.
I noticed words in columns got appended.
Example
Column1 | Column2
stack | overflow
Here the PdftextStripper would sometimes give me stackoverflow as extracted text. This would lead to bad tokinazation in solr which prevents you from finding the term. (Yes I know I can use wildcards but that doesn't work in phrase queries)
I have been looking at the sources to see what causes the problem. But it seems that the writePage method has to guess the spaces. I can't really change this since it seems very complex.
Are there any other solutions to get a good text extraction from a pdf with columns?
Maybe some sort of conversion other program.
Maybe patch for pdfbox.
Yes I've seen similar
question but they mostly handle the order of the extraction(which in
my case doesn't matter that much).
I got the same problem while extracting text with PDFbox. I solved this issue by taking the position information of each character. I took x position and y position of each character. And implemented a simple logic to distinguish words. Before that my word delimitter was only the " "(space). I added one more logic that if the difference of the X position of two characters are beyond a certain value (this value will be your choice.) and it is in the same line, that is same y coordinate (Different y coordinate means certainly a new word), I treated them as a new word. With this logic I was able to solve problems with table content, new line etc.
This link will help you to get the position of characters from pdf with PDFbox.

Categories