因为某些需要,需要用Java保存一些数据成Excel,听朋友说Apache POI Project 不错(以下下简称POI)
POI提供了一系列接口用于读取和生成微软的OLE 2 Compound Document format,就是Excel,Word..
因为现在只关心如何读取和生成Excel,所以就直接跳转到
http://poi.apache.org/hssf/index.html 超看如何使用HSSF
这是关于POI-HSSF的简单介绍
POI-HSSF - Java API To Access Microsoft Excel Format FilesOverviewHSSF is the POI Project's pure Java implementation of the Excel '97(-2002) file format. HSSF provides a way to read spreadsheets create, modify, read and write XLS spreadsheets It provides:
An alternate way of generating a spreadsheet is via the Cocoon serializer (yet you'll still be using HSSF indirectly). With Cocoon you can serialize any XML datasource (which might be a ESQL page outputting in SQL for instance) by simply applying the stylesheet and designating the serializer. If you're merely reading spreadsheet data, then use the eventmodel api in the org.apache.poi.hssf.eventusermodel package. If you're modifying spreadsheet data then use the usermodel api. You can also generate spreadsheets this way. |
在HSSF的页面内快速浏览了下,发现一个很不错的页面(正好是我需要的)
Busy Developers' Guide to HSSF Features
Busy Developers' Guide to Features
Want to use HSSF read and write spreadsheets in a hurry? This guide is for you. If you're after more in-depth coverage of the HSSF user-API please consult the HOWTO guide as it contains actual descriptions of how to use this stuff.
这个页面包含了大量的代码样例供没有时间查看API文档的程序员看的~~(非常不错的做法啊,人性化:0)
http://poi.apache.org/hssf/quick-guide.html
这是我用网页上代码样例(部分)copy出来的测试代码:)
执行后在工程文件文件夹内就成生成名为workbook.xls的Excel文件了
package blog.csdn.net.snailjava.hssf; import java.io.*; import org.apache.poi.hssf.usermodel.*; /** public class BusyDevTestHssf { public void createNewWork() { public void createNewSheet() { } catch (Exception e) { public void createCells() { // Create a row and put some cells in it. Rows are 0 based. // Or do it on one line. // Write the output to a file } catch (Exception e) { public void CreatDateCells() { // Create a row and put some cells in it. Rows are 0 based. // Create a cell and put a date value in it. The first cell is not styled // we style the second cell as a date (and time). It is important to // Write the output to a file public void createBorders() { // Create a row and put some cells in it. Rows are 0 based. // Create a cell and put a value in it. // Style the cell with borders all around. // Write the output to a file } public void createDifferentTypesOfCells() { // Write the output to a file public void createFillWithColor() { try { // Create a row and put some cells in it. Rows are 0 based. // Aqua background // Orange "foreground", foreground being the fill foreground not the font color. // Write the output to a file }
} |
老猪:因为Apache上的开源项目基本上都是无偿为人民服务的,所以作者都没有多少时间和精力去做详细教学和文档说明,HSSF的【Busy Developers' Guide to HSSF Features】这种形式的文档既简单,又直观,非常方便,是非常好的想法,以后自己写的代码的文档也可以借鉴下。