java操作Excel,設置Excel單元格樣式, 總行數、列數獲取


  Workbook workbook = null;

 workbook = WorkbookFactory.create(inputStream);
 Sheet sheet = workbook.getSheetAt(0);

CellStyle cellStyle2 = workbook.createCellStyle();

//設置背景色
cellStyle2.setFillForegroundColor(IndexedColors.RED.getIndex());
cellStyle2.setFillBackgroundColor(IndexedColors.RED.getIndex());
cellStyle2.setFillPattern(FillPatternType.SOLID_FOREGROUND);

//設置字體居中
cellStyle2.setAlignment(HorizontalAlignment.CENTER);
cellStyle2.setVerticalAlignment(VerticalAlignment.CENTER);
sheet.getRow(row).getCell(column).setCellStyle(cellStyle2);

//創建單元格,並賦值
Cell cwyy_cell = sheet.getRow(1).createCell(sheet.getRow(1).getLastCellNum());
cwyy_cell.setCellValue("錯誤原因");

//設置單元格的內容類型,字符串、數字或者其它
sheet.getRow(row).getCell(column).setCellType(CellType.STRING);
 //獲取總行數、總列數
int row_num_total = sheet.getLastRowNum();
int column_num_total = sheet.getRow(1).getLastCellNum();



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM