poi3.7处理excel文件
poi是apache下的一个开源处理excel的java框架
http://poi.apache.org/
下面是一个示例代码.
import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; public class TestExcel { public static void main(String[] args) throws Exception{ HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet(); workbook.setSheetName(0, "我的工作簿"); HSSFRow row = sheet.createRow(0); HSSFCell cell; //写入2列的第一行 cell = row.createCell(0); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue("第一列"); cell = row.createCell(1); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue("第二列"); //增加 第二行 row = sheet.createRow(1); cell = row.createCell(0); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue("1"); cell = row.createCell(1); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue("2"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); workbook.write(baos); byte[] b = baos.toByteArray(); File file= new File("c:/myExcel.xlsg"); FileOutputStream fos = new FileOutputStream(file); fos.write(b); } }
相关推荐
chenjia00 2020-07-04
Kafka 2020-09-18
Wepe0 2020-10-30
杜倩 2020-10-29
windle 2020-10-29
minerd 2020-10-28
mengzuchao 2020-10-22
Junzizhiai 2020-10-10
bxqybxqy 2020-09-30
风之沙城 2020-09-24
kingszelda 2020-09-22
大唐帝国前营 2020-08-18
yixu0 2020-08-17
TangCuYu 2020-08-15
xiaoboliu00 2020-08-15
songshijiazuaa 2020-08-15
xclxcl 2020-08-03
zmzmmf 2020-08-03
newfarhui 2020-08-03