+ All Categories
Home > Technology > Apache Poi Recipes

Apache Poi Recipes

Date post: 08-May-2015
Category:
Upload: paolo-mottadelli
View: 6,019 times
Download: 1 times
Share this document with a friend
Description:
Apache POI Recipes, presented at ApacheCon US 2009 in Oakland, gives a general description of Apache POI project and describes 3 use cases where POI functionalities are used in real applications.
69
Apache POI Recipes Paolo Mottadelli - ApacheCon Oakland 2009 http://chromasia.com Thursday, November 5, 2009
Transcript
Page 1: Apache Poi Recipes

Apache POIRecipesPaolo Mottadelli - ApacheCon Oakland 2009

http://chromasia.comThursday, November 5, 2009

Page 2: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

my to-do list

Thursday, November 5, 2009

Page 3: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

POI @ Content Tech

✴ Document to application (and back)✴ Publish data

✴ Build a doc from your content

✴ Know your documents✴ Extract text

✴ Extract content

Thursday, November 5, 2009

Page 4: Apache Poi Recipes

1A-B-C

Thursday, November 5, 2009

Page 5: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

POI modules (1): OLE2

✴ POIFS: reading/writing Office Documents

✴ HSSF r/w Excel Spreadsheets

✴ HWPF r/w Word Docs

✴ HSLF r/w PowerPoint Docs

✴ HPSF r/w property sets

Thursday, November 5, 2009

Page 6: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

POI modules (2): OOXML

✴ XSSF: r/w OXML Excel

✴ XWPF: r/w OXML Word

✴ XSLF: r/w OXML PowerPoint

Thursday, November 5, 2009

Page 7: Apache Poi Recipes

POI 3.5

http://chromasia.comThursday, November 5, 2009

Page 8: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

OOXML dev status

✴ XSSF: Final in POI-3.5

✴ XWPF: Draft (basic features)

✴ XSLF: Not covered (only text ext.)

Thursday, November 5, 2009

Page 9: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

HSSF & XSSF

✴ Common user model interface

✴ User model based on existing HSSF

✴ Using OpenXML4J and SAX

Thursday, November 5, 2009

Page 10: Apache Poi Recipes

2Same recipe, different flavours

Thursday, November 5, 2009

Page 11: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Common H/XSSF access

✴ org.apache.poi.ss.usermodel

Thursday, November 5, 2009

Page 12: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Upgrading to POI-3.5

✴ HSSFFormulaEvaluator.CellValue✴ convert from .hssf. to .ss.

✴ HSSFRow.MissingCellPolicy✴ convert from .hssf. to .ss.

✴ RecordFormatException in DDF✴ convert from .hssf. to .util. Dreadful Drawing Format

Thursday, November 5, 2009

Page 13: Apache Poi Recipes

3MeetOffice Open XML

Thursday, November 5, 2009

Page 14: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Open XML

✴ XML based✴ WordprocessingML

✴ SpreadsheetML

✴ PresentationML

✴ Stored as a package✴ Open Packaging Conventions

made (very) simple

Thursday, November 5, 2009

Page 15: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Package concepts

✴ Package (the container)

✴ Part (xml file)

✴ Relationship✴ package-relationship

✴ part-relationship

Thursday, November 5, 2009

Page 16: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Expanded package, Excel

Thursday, November 5, 2009

Page 17: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

WordprocessingML

✴ body✴ paragraphs

✴ runs

✴ properties (for runs and pars)

✴ styles

✴ headers/footers ...

Thursday, November 5, 2009

Page 18: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

SpreadsheetML

✴ workbook✴ worksheets

✴ rows

✴ cells

✴ styles

✴ formulas

✴ images ...

Thursday, November 5, 2009

Page 19: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

PresentationML

✴ presentation✴ slides

✴ slides-masters

✴ notes-masters

✴ layout, animation, audio, video, transitions ...

Thursday, November 5, 2009

Page 20: Apache Poi Recipes

4openxml4j

Thursday, November 5, 2009

Page 21: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

openXML4J

✴ Package, parts, rels

"/xl/worksheets/sheet1.xml"

Thursday, November 5, 2009

Page 22: Apache Poi Recipes

5Text Extraction

Thursday, November 5, 2009

Page 23: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Extractors

✴ POITextExtractor✴ POIOLE2TextExtractor

✴ POIXMLTextExtractor

✴ XSSFExcelExtractor

✴ XWPFWordExtractor

✴ XSLFPowerPointExtractor

✴ If text is all what you need

getText()

Thursday, November 5, 2009

Page 24: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Text extraction

✴ made simple

Thursday, November 5, 2009

Page 25: Apache Poi Recipes

6EXCELSimple Tasks

Thursday, November 5, 2009

Page 26: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

New Workbook

Thursday, November 5, 2009

Page 27: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

New Sheet

Thursday, November 5, 2009

Page 28: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Creating Cells

Thursday, November 5, 2009

Page 29: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Cell types

Thursday, November 5, 2009

Page 30: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Fills and colors

Thursday, November 5, 2009

Page 31: Apache Poi Recipes

7EXCELImp/Exp to XML

Thursday, November 5, 2009

Page 32: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Export to XML

Thursday, November 5, 2009

Page 33: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

xmlMaps.xml

Thursday, November 5, 2009

Page 34: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

XML Import/Export

Thursday, November 5, 2009

Page 35: Apache Poi Recipes

8WORDSimple Doc

Thursday, November 5, 2009

Page 36: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

A simple doc

Thursday, November 5, 2009

Page 37: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Thursday, November 5, 2009

Page 38: Apache Poi Recipes

9Use Case 1Alfresco Search

Thursday, November 5, 2009

Page 39: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Use Case

✴ Upload a document

✴ Detect document mimetype

✴ Extract text and metadata

✴ Create search index

✴ Search (and find) the document

Thursday, November 5, 2009

Page 40: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Without Tika✴ Detect the document mimetype

✴ (source/target mimetype)

✴ Get the proper ContentTransformer✴ (ContentTransformerRegistry)

✴ Tranform Doc Content to Text✴ (PoiHssfContentTransformer)

✴ Create Lucene indexPOI here

Thursday, November 5, 2009

Page 41: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

With Tika

Thursday, November 5, 2009

Page 42: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Extension use case

✴ Adding support for Office Open XML documents (Office 2007+)✴ Word 2007+

✴ Excel 2007+

✴ PowerPoint 2007+

Thursday, November 5, 2009

Page 43: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

POI text extractors

✴ Remember?

Thursday, November 5, 2009

Page 44: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Apache Tika (Excel)

Thursday, November 5, 2009

Page 45: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Apache Tika

Thursday, November 5, 2009

Page 46: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Apache Tika (Word)

Thursday, November 5, 2009

Page 47: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Apache Tika (Word)

Thursday, November 5, 2009

Page 48: Apache Poi Recipes

10Use Case 2JM LaffertyFinancial Forecasting

Thursday, November 5, 2009

Page 49: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Make your wb look pro-

✴ Rich text

✴ Graphics

✴ Formulas & Named Ranges

✴ Data validations

✴ Conditional formatting

✴ Cell comments

Thursday, November 5, 2009

Page 50: Apache Poi Recipes

Thursday, November 5, 2009

Page 51: Apache Poi Recipes

Thursday, November 5, 2009

Page 52: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Formula evaluation

✴ The evaluation engine enables you to calculate formula results from within a POI application

✴ Formulas may be added to your workbook by POI

✴ Evaluation is available for .xls and .xlsx

Thursday, November 5, 2009

Page 53: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Formula evaluation (continued)

✴ All arithmetic operators are implemented

✴ Over 280 Excel built in functions are supported

Thursday, November 5, 2009

Page 54: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Formula evaluation (code)

Thursday, November 5, 2009

Page 55: Apache Poi Recipes

11Use Case 3:CQ5 Import

Thursday, November 5, 2009

Page 56: Apache Poi Recipes

Thursday, November 5, 2009

Page 57: Apache Poi Recipes

Thursday, November 5, 2009

Page 58: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

importDocument()

Thursday, November 5, 2009

Page 59: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

getParagraphs(...)

✴ Makes use of✴ org.apache.poi.hwpf.usermodel.Range

Thursday, November 5, 2009

Page 60: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

importDocument()

Thursday, November 5, 2009

Page 61: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

getTitle(...)

✴ Gets the first paragraph’s text

Thursday, November 5, 2009

Page 62: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

importDocument()

Thursday, November 5, 2009

Page 63: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Thursday, November 5, 2009

Page 64: Apache Poi Recipes

Thursday, November 5, 2009

Page 65: Apache Poi Recipes

Thursday, November 5, 2009

Page 66: Apache Poi Recipes

12Want more?

Thursday, November 5, 2009

Page 67: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

More Examples

✴ http://poi.apache.org/spreadsheet/examples.html

Thursday, November 5, 2009

Page 68: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

Even more

✴ Get in touch✴ http://poi.apache.org/

✴ Get informed✴ [email protected]

✴ Get involved✴ http://svn.apache.org/repos/asf/poi/trunk/

Thursday, November 5, 2009

Page 69: Apache Poi Recipes

- ApacheCon US 2009, Oakland - Apache POI Recipes -

[email protected]

✴ Get slides✴ http://www.slideshare.net/paolomoz/apache-poi-recipes

Thanks

Thursday, November 5, 2009


Recommended