简单使用poi解析excel

POI结构
HSSF - 提供读写Microsoft Excel XLS格式档案的功能。
XSSF - 提供读写Microsoft Excel OOXML XLSX格式档案的功能。
HWPF - 提供读写Microsoft Word DOC格式档案的功能。
HSLF - 提供读写Microsoft PowerPoint格式档案的功能。
HDGF - 提供读Microsoft Visio格式档案的功能。
HPBF - 提供读Microsoft Publisher格式档案的功能。
HSMF - 提供读Microsoft Outlook格式档案的功能。

步骤一:访问apache网站,下载poi.Jar的类库

源代码

 

 

package com.txfy.PoiDemo;

import java.io.FileOutputStream;
import java.util.Calendar;
import java.util.Date;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

public class Createcell {
	public static void main(String args[]) throws Exception
	{
		Workbook workbook = new HSSFWorkbook();//创建一个工作簿
		FileOutputStream fiout = new FileOutputStream("c:\\工作簿.xls");
		Sheet sheet = workbook.createSheet("第一个sheet");//创建一个工作表
		Row row = sheet.createRow(0);//创建第一行,参数0表示行的索引,第一行
		Cell cell = row.createCell(0);//创建第一个单元格,参数0表示列的索引,第一列
		//给单元格设置值
		cell.setCellValue("你好");//给单元格设置字符串值
		row.createCell(1).setCellValue(1);//给单元格设置整型值
		row.createCell(2).setCellValue(1.3);//给单元格设置浮点型值
		row.createCell(3).setCellValue(false);//给单元格设置布尔型值
		//给单元格设置样式
		CellStyle cs = workbook.createCellStyle();
		CreationHelper ch = workbook.getCreationHelper();//获得工作簿的样式帮助类
		//对单元格日期的类型进行格式
		cs.setDataFormat(ch.createDataFormat().getFormat("yyyy-mm-dd hh:mm:ss"));
		//设置样式的语句在设置单元格的值前后均有效,一样的效果
		cell =row.createCell(4);
		cell.setCellStyle(cs);
		cell.setCellValue(new Date());
		cell = row.createCell(5);
		cell.setCellValue(Calendar.getInstance());
		cell.setCellStyle(cs);
		//将内存中工作簿的内容写到磁盘中
		workbook.write(fiout);
		fiout.close();
		
	}
}

 

 

 

 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值