POI Excel formula translated? - java

I am using German Excel 2007 and therefore the English formula are not evaluated automatically. In the German Excel I have no clue, where resp. how to get it working to evaluate English formulas.
So, I thought I am using the German ones, but this only throws a FormulaParsException. Setting the formula directly as cellvalue is obviously wrong, cause the content is not evaluated. I thought, perhaps I can turn off the evaluation resp. parsing, but no real success to it. I have seen, that I can write my own function, but to be honest, I wanna use an already built-in-function of Excel.
Can anybody give me a hint, how to use COUNTIF in German Excel? Resp. how to convince POI to accept ZAEHLENWENN?

Take a look at this question.
As stated in the answer, Apache POI doesn't support multiple languages, so you will have to use the English formulas to make it work.

Related

Excel 2016. Apostrophes in excel formula

I have an excel file with 2 pages.
The first page "sheet_n1" have formula with reference to another page =MAX(sheet_n2!A1:sheet_n2!A3)
The second page "sheet_n2" have a table with data.
After saving, I open my excel file as ZIP-archive. And in the XML-file of "sheet_n1" I have apostrophes in formula on second part of range =MAX(sheet_n2!A1:'sheet_n2'!A3)
This does not affect how the formula works in the excel. And I don't see these apostrophes in excel app.
But this affects opening a file using an Apache POI library in my Java application. I have apostrophes when I read a cell with formula
Can someone explain where these apostrophes come from ? And why only in the second part of the formula?
=MAX(17, 'sheet_n2'!A3) is correct syntax. The sheet name is surrounded by inverted commas. That's the rule.
However, Microsoft, in its never ending effort to make things easier, determined that they can be left out if there is no space in the tab name. The consequence is that Excel will remove the commas if there is no space in the name even if you type them. But if you use Excel in other languages, including VBA, the commas will not be removed even though they may not be needed. Appache POI is likely aware of this and would know how to deal with the commas.
=MAX(sheet_n2!A1:'sheet_n2'!A3) is a special case because the second mention of the sheet isn't required. =MAX(sheet_n2!A1:A3) is adequate. So, Excel doesn't quite know what to do with the extra information and leaves it untouched.

Replacing a text in Apache POI XWPF not working Extension

I am using the last answer which is available in link:
Replacing a text in Apache POI XWPF not working.
Thanks to Josh.
It is working perfect for almost all scenarios, but sometimes it is not applying the color to the replaced text properly.
am I missing something?
Runs are funny things. I know that the solution in this Stack Overflow question works great to replace sections of paragraphs or parts of runs that have different formatting (bold, embossed, etc) scattered throughout a given paragraph. For my particular use-case, the replace function was able to replace strings mid-run and handle any particular formatting that we were encountering. I didn't personally look at the color, but it appears to have functionality to do so: newRun.setColor(run.getColor());
Note that I originally was using Apache POI 3.11 and the code was giving me a lot of errors like "The method isEmbossed() is undefined for the type XWPFRun". Upgrading to 3.15 solved this.

Getting paragraph styles in apache POI, language specific

Is it possible to get the styles of a paragraph in a particular langage ?. For example: on my personal computer I happen to have a dutch installation of microsoft windows. this is resulting in the paragraph.getStyles() method returning the dutch values of the styles, instead of a normal value of "heading1", "heading2" etc I am receiving values such as"Kop1", "kop2".
I am creating a parser for word based documents which selects certain parts on style. does anyone have any experience with this ?
I would take a look at the data in the .docx file (it's a zip-file) to verify if the data is written this way by Word already or "transposed" by POI or some local functionality.
If the data is already written by Word you will need to check how you can create the document in a different language in Word.
If not, then if you are using POI 3.13 or newer, you can try to set a different locale via LocaleUtil.setUserLocale() and see if that affects the results.

What is the most _robust_ way to generate an Excel datafile from Java?

I have a situation where I have been asked to write a program that essentially does an arbitrary SQL select over JDBC, convert the ResultSet to something loadable in Excel and send it as an attachment in an email.
The question goes for what dataformat to use in order to be loadable by as many different versions of Excel as possible.
I have considered:
XLS - native format, the simplest way to generate seems to be with JExcel.
CSV - comma separated format, must use semicolons instead of commas to cope with European decimal commas, and then there is all the quotation stuff.
HTML - it appears that Excel knows how to read an HTML table. It should be sufficient then to set the MIME-type to be application/vnd.ms-excel
but naturally there must be other interesting ways to do it.
My major concern is incorrect interpretion of the data:
Numbers with decimal commas gets misinterpreted on systems with decimal points.
Character encoding issues (We cannot rely on the recipient using ISO-Latin-#).
Date interpretation - we have earlier found that the YYYY-MM-DD format is pretty robust.
My major concern is robustness. I don't mind it being tedious to code, if I can count on the result being good.
Suggestions and experiences to share?
I am aware of JSP generating Excel spreadsheet (XLS) to download - that page does not discuss robustness.
I'd recommend Andy Khan's JExcel. It's the best library for working with Excel in Java.
Apache hssf
This has always been the chosen method where I've worked in Java development.
It's an acronym for Horrible SpreadSheet Format
The quick way to generate Excel files to to write out tab delineated text and name it <name>.xls. Excel will open any text file ending in .xls as a single worksheet.

Apache POI HSSF/XSSF - Evaluating Formulas That Don't Live In Cells

With a known formula extracted from a spreadsheet, is it possible to apply/evaluate the formula without having it reside in an actual cell?
I suppose one can create / locate a blank cell on the sheet (anyone have any ideas how this might be done efficiently?) and evaluate the formula this way, but is there a better way?
I'm not sure that POI is the way to do for this, given that it looks after creating/reading/writing spreadsheets. Have you looked at invoking the Excel COM object (via, say, JACOB), and running the formulas in Excel itself ?
Excel does let you evaluate a formula without it having to reside in a cell. You can do it via the old XLM macro language with EVALUATE or through the C API, and via VBA with Application.Evaluate or Worksheet.Evaluate.
Of course, that information might be of no help if all you have is the extracted formula and not access to Excel. If you know the formulas will be simple enough, I can see evaluating them yourself or with another tool (although I don't know of anything specific). In general, though, you will need not only access to Excel, but also the actual document the formulas are in, since a formula can call user-written VBA/XLL functions, use defined names, etc.

Categories

Resources