POI的入门:创建单元格设置数据
生活随笔
收集整理的這篇文章主要介紹了
POI的入门:创建单元格设置数据
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
創(chuàng)建單元格?
//測(cè)試創(chuàng)建單元格 public static void main(String[] args) throws Exception {//1.創(chuàng)建workbook工作簿W(wǎng)orkbook wb = new XSSFWorkbook();//2.創(chuàng)建表單SheetSheet sheet = wb.createSheet("test");//3.創(chuàng)建行對(duì)象,從0開始Row row = sheet.createRow(3);//4.創(chuàng)建單元格,從0開始Cell cell = row.createCell(0);//5.單元格寫入數(shù)據(jù)cell.setCellValue("傳智播客");//6.文件流FileOutputStream fos = new FileOutputStream("E:\\test.xlsx");//7.寫入文件wb.write(fos);fos.close(); } package com.learn.poi.test;import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;import java.io.FileOutputStream;/*** 創(chuàng)建單元格寫入內(nèi)容*/ public class PoiTest02 {public static void main(String[] args) throws Exception {//創(chuàng)建工作簿 HSSFWorkbook -- 2003Workbook wb = new XSSFWorkbook(); //2007版本//創(chuàng)建表單sheetSheet sheet = wb.createSheet("test");//創(chuàng)建行對(duì)象 參數(shù):索引(從0開始)Row row = sheet.createRow(2);//創(chuàng)建單元格對(duì)象 參數(shù):索引(從0開始)Cell cell = row.createCell(2);//向單元格中寫入內(nèi)容cell.setCellValue("我和我的祖國");//文件流FileOutputStream pis = new FileOutputStream("C:\\Users\\leon\\Desktop\\00\\test1.xlsx");//寫入文件wb.write(pis);pis.close();} }?
總結(jié)
以上是生活随笔為你收集整理的POI的入门:创建单元格设置数据的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: POI的入门:概述和创建EXCEL
- 下一篇: DataURL:概述