poi将数据库数据导出excel文件
来源:互联网 发布:厦门网络教学平台登录 编辑:程序博客网 时间:2024/05/22 07:00
poi将数据库数据导出excel文件
excel文档 sheet row cell(单元格)
hssworkbook hssfsheet hssfrow hssfcell
所有版本poi-3.8
下载地址:http://www.apache.org/dyn/closer.cgi/poi/release/bin/poi-bin-3.8-
20120326.zip
导入所需jar包,根目录和lib目录下
示例代码如下:
/**
* writing a new file
*
* @time 1:50:24 PM
* @author retacn yue
* @Email zhenhuayue@sina.com
*/
public class App {
/**
* @param args
*/
public static void main(String[] args) {
// declare a workbook object reference
HSSFWorkbook workbook;
// declare a fos obj reference
FileOutputStream fos = null;
try {
// cerate a new file demo.xls
fos = new FileOutputStream("c:/demo.xls");
// create a new workbook
workbook = new HSSFWorkbook();
//if it is exist
//FileInputStream fis = new FileInputStream("c:/demo.xls");
//workbook = new HSSFWorkbook(fis);
// create a new sheet
HSSFSheet sheet = workbook.createSheet("demo1");
// declare a row object reference
Row row = null;
// declare a cell object reference
Cell cell = null;
// create three cell style
CellStyle cellStyle1 = workbook.createCellStyle();
CellStyle cellStyle2 = workbook.createCellStyle();
CellStyle cellStyle3 = workbook.createCellStyle();
DataFormat df = workbook.createDataFormat();
// create two fonts object
Font font1 = workbook.createFont();
Font font2 = workbook.createFont();
// set font 1 to 12 point type
font1.setFontHeightInPoints((short) 12);
// make it blue
font1.setColor((short) 0xc);
// make it bold
font1.setBoldweight(Font.BOLDWEIGHT_BOLD);
// set font 1 to 10 point type
font2.setFontHeightInPoints((short) 10);
// make it red
font2.setColor(Font.COLOR_RED);
// make it bold
font2.setBoldweight(Font.BOLDWEIGHT_BOLD);
font2.setStrikeout(true);
// set cell style
cellStyle1.setFont(font1);
// set cell format
cellStyle1.setDataFormat(df.getFormat("#,##0.0"));
// set a thin border
cellStyle2.setBorderBottom(cellStyle2.BORDER_THIN);
// fill w fg fill color
cellStyle2.setFillPattern(CellStyle.SOLID_FOREGROUND);
// set the sell format to text
cellStyle2.setDataFormat(HSSFDataFormat.getBuiltinFormat
("text"));
cellStyle2.setFont(font2);
// set sheetName
// workbook.setSheetName(0, "sheet1");
// create a sheet with 40 rows (0-39)
int rownum;
for (rownum = (short) 0; rownum < 40; rownum++) {
// create a row
row = sheet.createRow(rownum);
// on every other row
if ((rownum % 2) == 0) {
row.setHeight((short) 0x294);
}
}
rownum++;
sheet.createRow(rownum);
cellStyle3.setBorderBottom(cellStyle3.BORDER_THICK);
// create 50 cells
for (short cellnum = (short) 0; cellnum < 50; cellnum++) {
cell = row.createCell(cellnum);
// set it to thick black border style
cell.setCellStyle(cellStyle3);
}
// create a sheet,set its title then delete it
// sheet = workbook.createSheet();
// workbook.setSheetName(1, "deleteSheet");
// workbook.removeName(1);
workbook.write(fos);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
excel文档 sheet row cell(单元格)
hssworkbook hssfsheet hssfrow hssfcell
所有版本poi-3.8
下载地址:http://www.apache.org/dyn/closer.cgi/poi/release/bin/poi-bin-3.8-
20120326.zip
导入所需jar包,根目录和lib目录下
示例代码如下:
/**
* writing a new file
*
* @time 1:50:24 PM
* @author retacn yue
* @Email zhenhuayue@sina.com
*/
public class App {
/**
* @param args
*/
public static void main(String[] args) {
// declare a workbook object reference
HSSFWorkbook workbook;
// declare a fos obj reference
FileOutputStream fos = null;
try {
// cerate a new file demo.xls
fos = new FileOutputStream("c:/demo.xls");
// create a new workbook
workbook = new HSSFWorkbook();
//if it is exist
//FileInputStream fis = new FileInputStream("c:/demo.xls");
//workbook = new HSSFWorkbook(fis);
// create a new sheet
HSSFSheet sheet = workbook.createSheet("demo1");
// declare a row object reference
Row row = null;
// declare a cell object reference
Cell cell = null;
// create three cell style
CellStyle cellStyle1 = workbook.createCellStyle();
CellStyle cellStyle2 = workbook.createCellStyle();
CellStyle cellStyle3 = workbook.createCellStyle();
DataFormat df = workbook.createDataFormat();
// create two fonts object
Font font1 = workbook.createFont();
Font font2 = workbook.createFont();
// set font 1 to 12 point type
font1.setFontHeightInPoints((short) 12);
// make it blue
font1.setColor((short) 0xc);
// make it bold
font1.setBoldweight(Font.BOLDWEIGHT_BOLD);
// set font 1 to 10 point type
font2.setFontHeightInPoints((short) 10);
// make it red
font2.setColor(Font.COLOR_RED);
// make it bold
font2.setBoldweight(Font.BOLDWEIGHT_BOLD);
font2.setStrikeout(true);
// set cell style
cellStyle1.setFont(font1);
// set cell format
cellStyle1.setDataFormat(df.getFormat("#,##0.0"));
// set a thin border
cellStyle2.setBorderBottom(cellStyle2.BORDER_THIN);
// fill w fg fill color
cellStyle2.setFillPattern(CellStyle.SOLID_FOREGROUND);
// set the sell format to text
cellStyle2.setDataFormat(HSSFDataFormat.getBuiltinFormat
("text"));
cellStyle2.setFont(font2);
// set sheetName
// workbook.setSheetName(0, "sheet1");
// create a sheet with 40 rows (0-39)
int rownum;
for (rownum = (short) 0; rownum < 40; rownum++) {
// create a row
row = sheet.createRow(rownum);
// on every other row
if ((rownum % 2) == 0) {
row.setHeight((short) 0x294);
}
}
rownum++;
sheet.createRow(rownum);
cellStyle3.setBorderBottom(cellStyle3.BORDER_THICK);
// create 50 cells
for (short cellnum = (short) 0; cellnum < 50; cellnum++) {
cell = row.createCell(cellnum);
// set it to thick black border style
cell.setCellStyle(cellStyle3);
}
// create a sheet,set its title then delete it
// sheet = workbook.createSheet();
// workbook.setSheetName(1, "deleteSheet");
// workbook.removeName(1);
workbook.write(fos);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
- poi将数据库数据导出excel文件
- 【copy】利用poi将数据库数据导出excel
- 使用POI将数据导出到Excel文件
- 使用poi将数据导出到excel
- POI导出数据库数据到excel
- poi实现数据库数据导出到excel
- POI 导入导出Excel文件到数据库
- POI 导入导出Excel文件到数据库
- poi操作oracle数据库导出excel文件
- 使用POI将数据导入导出数据库。
- 用POI导出数据到excel文件
- 利用POI将数据库数据导入Excel
- 将数据库中的数据导出为excel文件 HSSFWorkBooK用法
- 将excel文件中的数据导入导出至SQL数据库
- java将数据库数据导出为Excel文件
- 将数据库中的数据导出为Excel文件
- POI EXCEL 数据导出
- poi导出excel数据
- 字符串朴素匹配算法
- javascript中的常用事例
- C#发送电子邮件 (异步)
- PC与Android模拟器UDP/TCP 通信的端口问题
- 织梦循环中图片不显示的问题
- poi将数据库数据导出excel文件
- http://www.cs.cmu.edu/puzzle/puzzle1.html
- criteria 用法
- mysql 出现表损坏解决方法:table 'xxx' is marked as crashed and should be repaired
- Lucene入门
- 网络论坛是什么?
- mysql数据库实现远程访问
- query 用法
- Amazon第二题