Reading, parsing, and extracting data from Excel files


Main Page | Discussion | Edit | History | Help | Switch to MediaWiki mode

Contents

Instantiate a new workbook

BookModel book = BookModel.Factory.create();
//or
JBook book = new JBook();

Access the document associated with a workbook

Document doc = book.getBook().getDocument();

Read workbook (SOD or XLS) from InputStream

Document doc = new Document(null, getServletContext().getResourceAsStream("/WEB-INF/templates/template.sod"), new DocumentOpenCallback());
BookModel book = BookModel.Factory.create(doc.getBook());

Read workbook (SOD or XLS) from filesystem

Document doc = new Document(null, path/file.sod, new DocumentOpenCallback());
BookModel book = BookModel.Factory.create(doc.getBook());

Read from BLOB

The byte array represents the spreadsheet. This byte array could come from a file upload mechanism, a spreadsheet stored in a database, etc.

Document doc = new Document(null, bytearray, new DocumentOpenCallback());
BookModel book = BookModel.Factory.create(doc.getBook());

Write to BLOB

Calling writeToBlob returns a byte array allowing you to store in a database, serialize in session, etc.

doc.fileSaveCopyAsByteArray(DocumentType.EXCEL_97_WORKBOOK, new DocumentSaveCallback());

Get the contents of the active cell

book.getEntry();

Get the value of the specified cell as it appears in the specified worksheet

book.getFormattedText(int sheet, int row, int col);

Get the text of the formula of the specified cell in the specified sheet, in US English

book.getFormula(int sheet, int row, int col);

Get the numeric value of the specified cell in the specified worksheet

book.getNumber(int sheet, int row, int col);

Get the text value of the specified cell

book.getText(int sheet, int row, int col);

Returns the value of the specified cell on the specified worksheet in edit mode format

book.getEntry(int sheet, int row, int col);

Get the index of the currently selected sheet

book.getSheet();

Select a worksheet

book.setSheet(int sheet);

Get the contents of a cell using a defined name

book.getEntry("DefinedName");

Write out a range as XML

XMLWriter xmlWriter = new XMLWriter(book.getBook());
xmlWriter.setWriteFormatAttributes(true);
xmlWriter.write("A1:T40", out);

Retrieved from "http://www.birt-exchange.com/wiki/Reading%2C_parsing%2C_and_extracting_data_from_Excel_files/"

This page has been accessed 3,933 times. This page was last modified 04:52, 29 November 2007.