poi导出数据
1.poi導(dǎo)出excel
/**
* 2003格式
*/
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*;
import java.io.FileOutputStream;
import java.io.IOException;
public class poi
{
public static void main(String[] args) throws IOException
{
// 新建工作表對(duì)象
HSSFWorkbook book = new HSSFWorkbook();
// 自定義sheet
Sheet sheet = book.createSheet("自定義1");
//創(chuàng)建行
Row row = sheet.createRow(0);
//創(chuàng)建單元格
Cell cell = row.createCell(0);
cell.setCellValue("單元格測(cè)試值");
HSSFCellStyle cellStyle = book.createCellStyle();
cellStyle.setFillForegroundColor((short) 13);// 設(shè)置背景色
cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下邊框
cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左邊框
cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上邊框
cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右邊框
//設(shè)置居中:
cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中
//設(shè)置字體:
HSSFFont font = book.createFont();
font.setFontName("黑體");
font.setFontHeightInPoints((short) 16);//設(shè)置字體大小
HSSFFont font2 = book.createFont();
font2.setFontName("仿宋_GB2312");
font2.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗體顯示
font2.setFontHeightInPoints((short) 12);
// 使字體生效
cellStyle.setFont(font);//選擇需要用到的字體格式
// 使樣式生效
cell.setCellStyle(cellStyle);
//構(gòu)建文件
FileOutputStream fileout = new FileOutputStream("D://test.xls");
// 將工作表兌現(xiàn)寫入文件中
book.write(fileout);
}
} ?
響應(yīng)結(jié)果:
依賴jar包:
參考資料
?demo:
鏈接:https://pan.baidu.com/s/1jkgclbfsMbDP0f38wGcI4A
提取碼:5i8n
轉(zhuǎn)載于:https://www.cnblogs.com/nevegiveup/p/6928321.html
總結(jié)
- 上一篇: 微信OAuth2网页授权登陆接口
- 下一篇: (数字IC)低功耗设计入门(八)——物理