Working with Microsoft Excel spreadsheets and Microsoft Access databases in a Java application Sean...
-
Upload
diana-mclaughlin -
Category
Documents
-
view
229 -
download
2
Transcript of Working with Microsoft Excel spreadsheets and Microsoft Access databases in a Java application Sean...
![Page 1: Working with Microsoft Excel spreadsheets and Microsoft Access databases in a Java application Sean Sullivan July 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062713/56649cf45503460f949c308d/html5/thumbnails/1.jpg)
Working with Microsoft Excel spreadsheets and Microsoft Access databases in a Java application
Sean SullivanJuly 27, 2006
![Page 2: Working with Microsoft Excel spreadsheets and Microsoft Access databases in a Java application Sean Sullivan July 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062713/56649cf45503460f949c308d/html5/thumbnails/2.jpg)
This presentation is available athttp://oscon2006.sourceforge.net/
![Page 3: Working with Microsoft Excel spreadsheets and Microsoft Access databases in a Java application Sean Sullivan July 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062713/56649cf45503460f949c308d/html5/thumbnails/3.jpg)
•Introduction
•Jakarta POI project
•Jackcess project
•Demo: web application
•Demo: Swing application
Overview
![Page 4: Working with Microsoft Excel spreadsheets and Microsoft Access databases in a Java application Sean Sullivan July 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062713/56649cf45503460f949c308d/html5/thumbnails/4.jpg)
•Java class library for reading and writing Microsoft Office documents
•Apache License 2.0
•http://jakarta.apache.org/poi
Jakarta POI
![Page 5: Working with Microsoft Excel spreadsheets and Microsoft Access databases in a Java application Sean Sullivan July 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062713/56649cf45503460f949c308d/html5/thumbnails/5.jpg)
•Read/write OLE2 Compound Document Format
•Read/write Microsoft Office documents
• XLS
• PPT
• DOC
•Not supported
• MDB
• VSD
POI features
![Page 6: Working with Microsoft Excel spreadsheets and Microsoft Access databases in a Java application Sean Sullivan July 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062713/56649cf45503460f949c308d/html5/thumbnails/6.jpg)
Who is using Jakarta POI?
![Page 7: Working with Microsoft Excel spreadsheets and Microsoft Access databases in a Java application Sean Sullivan July 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062713/56649cf45503460f949c308d/html5/thumbnails/7.jpg)
•POIFS: low-level file I/O
•HSSF: Horrible Spreadsheet Format
•HWPF: Horrible Word-processing Format
•HSLF: Horrible Slide Format
•HPSF: Horrible Property Set Format
•DDF: Dreadful Drawing Format
POI terminology
![Page 8: Working with Microsoft Excel spreadsheets and Microsoft Access databases in a Java application Sean Sullivan July 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062713/56649cf45503460f949c308d/html5/thumbnails/8.jpg)
Microsoft Excel file format
222 pages!
![Page 9: Working with Microsoft Excel spreadsheets and Microsoft Access databases in a Java application Sean Sullivan July 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062713/56649cf45503460f949c308d/html5/thumbnails/9.jpg)
Packages
• org.apache.poi.hssf• org.apache.poi.hssf.eventusermodel• org.apache.poi.hssf.usermodel
Core classes
• HSSFWorkbook• HSSFSheet• HSSFRow• HSSFCell• HSSFCellStyle
Working with XLS files
![Page 10: Working with Microsoft Excel spreadsheets and Microsoft Access databases in a Java application Sean Sullivan July 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062713/56649cf45503460f949c308d/html5/thumbnails/10.jpg)
Demo: Hello POI
@see HelloPoi.java
![Page 11: Working with Microsoft Excel spreadsheets and Microsoft Access databases in a Java application Sean Sullivan July 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062713/56649cf45503460f949c308d/html5/thumbnails/11.jpg)
Yes!
HSSFCell• getCellFormula• setCellFormula("formulaString")
HSSFFormulaEvaluator • evaluate(HSSFCell)
Can I use formulas?
![Page 12: Working with Microsoft Excel spreadsheets and Microsoft Access databases in a Java application Sean Sullivan July 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062713/56649cf45503460f949c308d/html5/thumbnails/12.jpg)
•Macros - must load from a template XLS file
•Charts - limited support
•Pivot tables - not supported
Other POI topics
![Page 13: Working with Microsoft Excel spreadsheets and Microsoft Access databases in a Java application Sean Sullivan July 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062713/56649cf45503460f949c308d/html5/thumbnails/13.jpg)
•Java class library for reading and writing MDB files
•developed by Health Market Science Inc.
•LGPL
•requires JRE 1.5 or higher
•http://jackcess.sourceforge.net/
Jackcess project
![Page 14: Working with Microsoft Excel spreadsheets and Microsoft Access databases in a Java application Sean Sullivan July 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062713/56649cf45503460f949c308d/html5/thumbnails/14.jpg)
•Read/write Microsoft Access MDB files*
•Copy ResultSet to MDB table
•Copy CSV file to MDB table
Jackcess features
* Microsoft Access 2000 only
![Page 15: Working with Microsoft Excel spreadsheets and Microsoft Access databases in a Java application Sean Sullivan July 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062713/56649cf45503460f949c308d/html5/thumbnails/15.jpg)
Package:
com.healthmarketscience.jackcess
Core classes:
• Database• Table• Column• DataType
Jackcess API
![Page 16: Working with Microsoft Excel spreadsheets and Microsoft Access databases in a Java application Sean Sullivan July 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062713/56649cf45503460f949c308d/html5/thumbnails/16.jpg)
Hello JackcessDatabase db = Database.open(new File("demo.mdb"));for (String tname: db.getTableNames()){ Table t = db.getTable(tname); Map<String, Object> row; while ((row = t.getNextRow()) != null) { for (String colName : row.keySet()) { System.out.println(row.get(colName)); } }}
![Page 17: Working with Microsoft Excel spreadsheets and Microsoft Access databases in a Java application Sean Sullivan July 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062713/56649cf45503460f949c308d/html5/thumbnails/17.jpg)
•Eclipse 3.2
•WebTools 1.5
•Subversion 1.3.x
•Subclipse 1.1.x
•Tomcat 5.5.17
•Firefox 1.5.0.5
•Maven 2.0.4
Web application demo
•POI 3.0 alpha 2
•Jackcess 1.1.5
•OpenCSV 1.5
•Wicket 1.2
•Derby 10.1.2.1
•Log4j 1.2.13
•Sun JDK 1.5
![Page 18: Working with Microsoft Excel spreadsheets and Microsoft Access databases in a Java application Sean Sullivan July 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062713/56649cf45503460f949c308d/html5/thumbnails/18.jpg)
•javax.swing.JTable
•javax.swing.table.TableModel
•Jakarta POI
Swing demo
![Page 19: Working with Microsoft Excel spreadsheets and Microsoft Access databases in a Java application Sean Sullivan July 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062713/56649cf45503460f949c308d/html5/thumbnails/19.jpg)
Summary
• Use POI to read/write XLS files
http://jakarta.apache.org/poi/
• Use Jackcess to read/write MDB files
http://jackcess.sourceforge.net/
• This presentation
http://oscon2006.sourceforge.net/