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.
Related
I have a scenario to run assertions on the Actual data that is provided in XLS file against the Expected Data provided in XLSX file basing on an identifier column in Java. Can anyone provide any advice or suggestion on this please?
Actual Data
Field(Name) Field(Identifier) Entity(Name) ParentEntity(Name)
Lead time Article.DeliveryTime Item None
Expected Data
Field(Name) Field(Identifier) Entity(Name) ParentEntity(Name)
Lead time Article.DeliveryTime Item ParentQualifier
The number of Rows and columns might change basing on the data provided, but the Field(Identifier) would be given in both the files.
I suggest converting the Excel files to some more structured format such as *.csv. You can do that with Excel by just saving it to *.csv. There are many CSV parser libraries.
If that is not possible for some reason (not owner of data, management,...) you could use Apache POI to parse the *.xls / *.xlsx files and then do the testing. How to shown here Link1 or here Link2. Then you can simply run the assertions with JUnit.
There are two potential problems though:
Changing columns: You need to parse the Excel without specifying exact column names. Then only compare columns that have the same name.
Data doesn't fit in memory: Search for id's and only load matching rows.
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.
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
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.
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.