java如何使用poi對(duì)Execl簡(jiǎn)單寫(xiě)操作
如何進(jìn)行Java使用poi對(duì)Execl簡(jiǎn)單寫(xiě)操作呢?下面是小編給大家提供的代碼,大家可以參考閱讀,更多詳情請(qǐng)關(guān)注應(yīng)屆畢業(yè)生考試網(wǎng)。
java使用poi對(duì)Execl簡(jiǎn)單寫(xiě)操作
public class WriteExecl {
public void writeExeclTest() throws Exception{
OutputStream os = new FileOutputStream("F:/execl/writeTest2.xlsx");
/pic/pic/p>
Workbook wb = new XSSFWorkbook(); /pic/p>
CellStyle cellStyle = wb.createCellStyle(); /pic/p>
cellStyle.setBorderLeft(CellStyle.BORDER_THIN); /pic/p>
cellStyle.setBorderRight(CellStyle.BORDER_THIN);/pic/p>
cellStyle.setBorderTop(CellStyle.BORDER_THIN);/pic/p>
cellStyle.setBorderBottom(CellStyle.BORDER_THIN);/pic/p>
cellStyle.setAlignment(CellStyle.ALIGN_CENTER); /pic/p>
cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); /pic/p>
cellStyle.setBottomBorderColor(IndexedColors.RED.getIndex()); /pic/p>
cellStyle.setFillForegroundColor(IndexedColors.DARK_YELLOW.getIndex()); /pic/p>
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); /pic/p>
Sheet sheet = wb.createSheet("第一個(gè)sheet"); /pic/p>
sheet.setDefaultColumnWidth(1000); /pic/p>
sheet.setDefaultRowHeight((short) 800); /pic/p>
Row row = sheet.createRow(0); /pic/p>
row.createCell(0, Cell.CELL_TYPE_BLANK); /pic/p>
row.createCell(1, Cell.CELL_TYPE_BOOLEAN).setCellValue(true); /pic/p>
row.createCell(2, Cell.CELL_TYPE_FORMULA).setCellValue(3.141592653); /pic/p>
row.createCell(3, Cell.CELL_TYPE_NUMERIC).setCellValue(0); /pic/p>
row.createCell(4, Cell.CELL_TYPE_STRING).setCellValue("String..."); /pic/p>
row.setRowStyle(cellStyle); /pic/p>
wb.write(os); /pic/p>
os.close(); /pic/p>
}
}
【java如何使用poi對(duì)Execl簡(jiǎn)單寫(xiě)操作】相關(guān)文章:
如何使用java12-19
如何使用java多線程10-09
如何正確使用Java數(shù)組10-04
淺談如何使用java多線程08-04
Java中如何使用嵌入MySQL08-27
如何使用一個(gè)java11-28
Java入門(mén)教程:如何使用一個(gè)Java02-18