POI 간이 도움말 문서 시리즈 - Excel에 스타일 설정

1671 단어
클릭하여 링크 열기
package com.myjava.poi;

import java.io.FileOutputStream;
import java.util.Calendar;
import java.util.Date;

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.CreationHelper;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

public class Border {

    public static void main(String[] args) throws Exception{
        Workbook wb=new HSSFWorkbook(); //  
        Sheet sheet=wb.createSheet(" Sheet ");  //  Sheet 
        Row row=sheet.createRow(1); //  
        
        Cell cell=row.createCell(1); //  
        cell.setCellValue(4);
        
        CellStyle cellStyle=wb.createCellStyle(); 
        cellStyle.setBorderBottom(CellStyle.BORDER_THIN); //  
        cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); //  
        
        cellStyle.setBorderLeft(CellStyle.BORDER_THIN);  //  
        cellStyle.setLeftBorderColor(IndexedColors.RED.getIndex()); //  
        
        cellStyle.setBorderRight(CellStyle.BORDER_THIN); //  
        cellStyle.setRightBorderColor(IndexedColors.BLUE.getIndex());  //  
        
        cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM_DASHED); //  
        cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());  //  
        
        cell.setCellStyle(cellStyle);
        FileOutputStream fileOut=new FileOutputStream("D:\\Border.xls");
        wb.write(fileOut);
        fileOut.close();
    }
}

좋은 웹페이지 즐겨찾기