【poi第五节】poi设置Excel单元格边框 和 背景色,java设置Excel 单元格边框 和 背景色
生活随笔
收集整理的這篇文章主要介紹了
【poi第五节】poi设置Excel单元格边框 和 背景色,java设置Excel 单元格边框 和 背景色
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
poi設置Excel單元格邊框 和 背景色,java設置Excel 單元格邊框 和 背景色
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.ss.usermodel.BorderStyle; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.FillPatternType; 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;import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.OutputStream;/*** @ClassName 類名:ExcelDemo5* @Author作者: hzh* @Date時間:2018/12/4 13:41* 單元格邊框 和 背景色**/ public class ExcelDemo5 {public static void main(String[] args) throws Exception {Workbook wb = new HSSFWorkbook();Sheet sheet = wb.createSheet("一個sheet");Row row = sheet.createRow(3); //第一行Cell cell = row.createCell(3); //第一列cell.setCellValue("哈哈");CellStyle cellStyle = wb.createCellStyle(); //創建一個樣式cellStyle.setBorderBottom(BorderStyle.DOUBLE); //底部邊框cellStyle.setBottomBorderColor(HSSFColor.YELLOW.index);//底部邊框顏色cellStyle.setBorderLeft(BorderStyle.MEDIUM_DASH_DOT_DOT); //左邊框cellStyle.setLeftBorderColor(HSSFColor.RED.index);//左邊框顏色cellStyle.setFillForegroundColor(IndexedColors.RED.getIndex()); //設置背景色cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);cell.setCellStyle(cellStyle);FileOutputStream fileOutputStream = new FileOutputStream("D://file//工作薄2.xls");wb.write(fileOutputStream);wb.close();}}?
總結
以上是生活随笔為你收集整理的【poi第五节】poi设置Excel单元格边框 和 背景色,java设置Excel 单元格边框 和 背景色的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 乘法逆元的几种计算方法
- 下一篇: 移动onelink自动化脚本,机卡分离解