【web開發】☆★之利用POI操作Excel表格系列教程【9】儲存格邊框處理

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.