Fast Excel-Yet Another Excel Read/Write Component.

SourceForge.net Logo

Abstract

FastExcel is a pure java excel read/write component.It's FAST and TINY. We provide:

FastExcel 0.5.1 Release
DOWNLOAD

FastExcel is content-based,that means we just care about the content of excel. So FastExcel just read the cell string and other important information,Some Properities like color,font are not supported.Because we don't need to read,parse,store these additional information so FastExcel just need little memory.

New Features in FastExcel 0.4

Table of Contents

About FastExcel

FastExcel is a pure java excel read/write component.We provide reading and writing Excel[1]'97(-2003) (BIFF8[2]) file format and a low level API for compound document file format[3][4].It license under the term of LGPL.
For more information contract yAma,HeDYn,Visit BLOG

How it works

A workbook document with several sheets (BIFF5-BIFF8) is usually stored using the compound document file format (also known as "OLE2 storage file format" or "Microsoft Office compatible storage file format"). It contains several streams for different types of data.Depending on the document type, different names are used for the stream(s) they contain. BIFF5-BIFF8 workbook documents that are stored in a compound document file contain a stream in the root storage called the Workbook Stream. The name of this stream in the compound document file is "Book" for BIFF5 workbooks, and "Workbook" for BIFF8 workbooks.If a BIFF5-BIFF8 workbook document is stored as stream file, the entire stream is called the Workbook Stream. In BIFF5-BIFF8 Workbook Streams, the Workbook Globals Substream is not the leading part of the stream. It is followed by all Sheet Substreams in order of the sheets that are in the document. Common structure of a BIFF5-BIFF8 Workbook Stream:

Most of the Excel streams or substreams are divided into records. Each record contains specific data for the various contents or features in a document. It consists of a header specifying the record type and size, followed by the record data. Common structure of a BIFF record:

Offset Size Contents
0 2 Identifier
2 2 Size of the following data (sz)
4 sz Record data

To read excel file.FastExcel parses these records and build an inner struct of excel file.The Record Parsers:

Example

Basic Read

public void testDump() throws ExcelException {
	Workbook workBook;
	workBook = FastExcel.createReadableWorkbook(new File("test.xls"));
	workBook.setSSTType(BIFFSetting.SST_TYPE_DEFAULT);//memory storage
	workBook.open();
	Sheet s;
	s = workBook.getSheet(0);
	System.out.println("SHEET:"+s);
	for (int i = s.getFirstRow(); i < s.getLastRow(); i++) {
	System.out.print(i+"#");
	for (int j = s.getFirstColumn(); j < s.getLastColumn(); j++) {
		System.out.print(","+s.getCell(i, j));
	}
	System.out.println();
	}
	workBook.close();
}
	

Event-based Read

public void testEventDump() throws ExcelException {
		Workbook workBook;
		workBook = FastExcel
				.createReadableWorkbook(new File("test.xls"));
		workBook.open();
		workBook.getSheet(0, new SheetReadAdapter() {
			public void onCell(int row, int col, String content) {
				System.out.println(row + "," + col + "," + content);
			}
		});
		workBook.close();
	}
	

Basic Write

public void testWrite() throws ExcelException{
		File f=new File("write.xls");
		Workbook wb=FastExcel.createWriteableWorkbook(f);
		wb.open();
		Sheet sheet=wb.addSheet("sheetA");
		sheet.setCell(1, 2, "some string");
		wb.close();
	}
	

Stream Write

public void testStreamWrite() throws Exception{
		File f=new File("write1.xls");
		Workbook wb=FastExcel.createWriteableWorkbook(f);
		wb.open();
		Sheet sheet=wb.addStreamSheet("SheetA");
		sheet.addRow(new String[]{"aaa","bbb"});
		wb.close();
	}	

Download

FastExcel 0.5.1 Release

click here

References

  1. http://en.wikipedia.org/wiki/Microsoft_Excel.
  2. http://sc.openoffice.org/excelfileformat.pdf
  3. http://sc.openoffice.org/compdocfileformat.pdf
  4. http://blog.csdn.net/liangjingbo/archive/2008/09/03/2874959.aspx

©Copyright 2008-2011 - yAma, All Rights Reserved