【poi 제10절】poi 조작 excel 설정 데이터 형식, 금액 데이터 형식

1593 단어 POIexcel
poi 작업 excel 설정 데이터 형식, 금액 데이터 형식
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.DataFormat;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.FileOutputStream;

/**
 * @ClassName  :ExcelDemo10
 * @Author : hzh
 * @Date :2018/12/4 16:15
 *  
 **/
public class ExcelDemo10 {

    public static void main(String[] args) throws Exception{
        // 
        Workbook wb = new HSSFWorkbook();
        // sheet
        Sheet sheet = wb.createSheet(" sheet");

        CellStyle cellStyle;
        DataFormat format = wb.createDataFormat();
        Row row;
        Cell cell;
        short rowNum = 0;
        short colNum = 0;
        row = sheet.createRow(rowNum++);
        cell = row.createCell(colNum);
        cell.setCellValue(111111111111.25);

        cellStyle = wb.createCellStyle();
        cellStyle.setDataFormat(format.getFormat("0.0")); // 
        cell.setCellStyle(cellStyle);

        row = sheet.createRow(rowNum++);
        cell = row.createCell(colNum);
        cell.setCellValue(111111111111.25);
        cellStyle = wb.createCellStyle();
        cellStyle.setDataFormat(format.getFormat("#,##0.00")); // 
        cell.setCellStyle(cellStyle);

        FileOutputStream fileOutputStream = new FileOutputStream("D://file// .xls");
        wb.write(fileOutputStream);
        wb.close();
    }
}

좋은 웹페이지 즐겨찾기