標籤:poi儲存格邊框處理
【web開發】☆★之利用POI操作Excel表格系列教程【9】儲存格邊框處理
package csg.xiaoye.poidemo;import java.io.FileOutputStream;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.IndexedColors;import org.apache.poi.ss.usermodel.Row;import org.apache.poi.ss.usermodel.Sheet;import org.apache.poi.ss.usermodel.Workbook;/** * 處理儲存格邊框 * @author Administrator * */public class PoiFrame { 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_DASH_DOT_DOT); // 右邊邊框 cellStyle.setRightBorderColor(IndexedColors.BLUE.getIndex()); // 右邊邊框顏色 cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM_DASHED); // 上邊邊框 cellStyle.setTopBorderColor(IndexedColors.ORANGE.getIndex()); // 上邊邊框顏色 cell.setCellStyle(cellStyle); FileOutputStream fileOut=new FileOutputStream("d:\\小夜.xls"); wb.write(fileOut); fileOut.close(); }}
效果如下:
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/26/90/wKioL1Nrfx3gxIqAAAAnCNCWYBY546.jpg" title="1.png" alt="wKioL1Nrfx3gxIqAAAAnCNCWYBY546.jpg" />
本文出自 “諾言永遠依戀小柴、、、” 部落格,請務必保留此出處http://1936625305.blog.51cto.com/6410597/1408594