Groovy - writing and formatting excel 2010 - java

What are th options for working with an excel workbook from within a groovy (java) environment? We would like to be able to use the following features
add sheets
add cells: headings and data
format columns, rows, cells
and potentially
form pivot tables
copy the pivot table by value
paste clipboard by value on another screen
Essentially this will allow us to forma pivot table but remove the underlying data from the worksheet.
Thoughts? Thanks in advance.

Try apache poi. Can definitely perform your first list of requirements. I have used this api a good bit. If you have any questions, please feel free to ask.

Several Java libraries are available to handle the requirements you're looking for:
Apache POI
OpenOffice API
JExcelAPI
Jacob
...
Not sure which one can easily handle pivot tables.
Good luck with your project!
Wim

This page describes some more Groovy-specific options, but my recommendation would be to use Apache POI, either from Java or Groovy

Related

x4j-analytic and muti-page excel reports with charts

I have used JXLS to try to create a multi-page report with a chart in each sheet but it failed.
Imagine a scenario where you have data about monthly sales about a few products,
so each tab would be a Month and then each month would have a chart about sales of the products.
So I am looking for a Java API that can clone a template chart and put copies of these into separate sheets/tabs.
I was able to create the multiple sheets based on a template file, and was able to get the chart to be copied to each sheet from the template, but the "range literal string" that needs to be put into the Chart series was not dynamic in that it had the same reference to the first sheet from the original template.
When I spoke to the Author of JXLS he said he will try to look into it, but it has been over 1.5 years now and no progress.
My question is if anybody knows if "x4j-analytic" can create such reports.
I hope the author of this project: jbaliuka, can make some comments on this.
There is another java excel reporting project called JETT, I posed the same question on their forum/mailing list, but the author Randy Gettman does not seem to be actively looking at it.
Sincerely,
Palu
x4j-analytic library does not support dynamic sheets too. I normally use pivot with dynamic columns to display such data, pivot charts should work too. Dynamic sheets might be useful to workaround Excel limitations for very huge reports but I did not have such problem in practice and this feature is unimplemented.

Reading excel data from multiple related excel sheets and dumping in java classes

I have an excel file which contain multiple sheets. I want to relate these sheets with each other Ex.
Here master is the root table, I will read the last column, if the names in it matches with the any tab name I will read the tab .
and atlast I will dump the data in some java classes which will represent these excel sheets.
So when i will use the data in code it will be get by. Master.Polygon.Cord etc.
Please suggest a way for it using POI .
You can use a combination of getSheetIndex(name) and getSheetAt(index) using the HSSFWorkbook class
http://poi.apache.org/apidocs/index.html
You can use
if(workbook.getSheet(cell.toString())!=null){
sheet=wb.getSheet(cell.toString());
//code after getting the sheet
}
I think you gave up too early. Whenever you are doing development the documentation is your best friend. You can always look at few examples. Its a straight forward task you just have to load the excel file and extract sheet by sheet and perform you task. You can also look on some tutorials for jxl they are very similar for beginners.

Using Apache POI HSSF, how can I refresh all formula cells at once?

I am filling cells of an Excel file using Apache POI, and there are a lot of formula cells in the document. However, their values are not refreshed when I open the document in Excel.
It's my understanding that I need to use a FormulaEvaluator to refresh formula cells. Is there a way, though, to update all formula cells at once? There are a lot of them, and while making an exhaustive list is not out of question, it's certainly not something I'm very willing to do.
Sure. Refreshing all the formulas in a workbook is possibly the more typical use case anyway.
If you're using HSSF, call evaluatorAllFormulaCells:
HSSFFormulaEvaluator.evaluateAllFormulaCells(hssfWorkbook)
If you're using XSSF, call evaluatorAllFormulaCells:
XSSFFormulaEvaluator.evaluateAllFormulaCells(xssfWorkbook)
More details are available on the poi website
wb.setForceFormulaRecalculation(true);
// replace "wb" with your HSSFWorkbook/XSSFWorkbook object
https://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFWorkbook.html#setForceFormulaRecalculation-boolean-
https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFWorkbook.html#setForceFormulaRecalculation-boolean-

POI and Excel Lists or Tables

There is a requirement to read multiple Excel "Lists" from one sheet in an Excel file.
I need to know if there is an inbuilt method/api to obtain the dimensions of a list or deal with list specific data. At the bare minimum, is there a way of knowing the "headers" of the list and the number of rows contained in the list data?
I want the POI wrapper that I am writing to be aware of the data elements on the excel, rather than being told through properties/constants or worse; hardcoding the names of the headers/size of the list.
Regards, Vinu
PS: No idea whether the question made any sense...but anyone who gets my drift...please!
I've just written something to do this. AFAIK, Poi itself doesn't understand lists/tables, but you can easily write a wrapper that does. Alternatively, there is the jxls project - this allows complex mappings from POJOs to spreadsheets, and has table reader functionality.
How to: Excel Files has a number of links to projects that might be useful, including an Excel JDBC driver.

POI dynamic templates

Can anyone tell me where do I find some useful documentation on handling copying rows, cells, columns from one excel file to another, using POI?
I need to insert in one blank excel file, 2 or more templates from other files, dynamic.
I also need to keep all the styles made for the group of cells that I copy. How can I do that? Nothing found on apache poi tutorial on this point.
I am using POI 3.0.1.
Thank you!
I assume the problem is data types and merged cells? It's easy enough to get and set styles and set values.
Depending on your use case, you might be able to take entire sheets from the original document, assemble the new document from those and tweak it to your liking. Even if you have to combine multiple source sheets into one target sheet, you might still be able to retrieve source rows and assemble the target document from those rows.
...that was me some time ago...
I never could copy from one excel file to another with the exact style, but I found a solution : I used multiple worksheets instead of multiple excel files, cause style has no problem in being copied from one sheet to another as long as it is in the same workbook.
I also migrated from POI3.0.1 to POI 3.6. Far much better.

Categories

Resources