Java apachepoi中的设置样式
我正在为标题设置样式,我最后一列中的一列也得到了我为标题设置的样式。这是我设置样式的代码Java apachepoi中的设置样式,java,excel,apache-poi,Java,Excel,Apache Poi,我正在为标题设置样式,我最后一列中的一列也得到了我为标题设置的样式。这是我设置样式的代码 XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet(sheetName); for (int i = 0; i < numberOfMergedRow; i++) { sheet.addMergedRegion(new CellRangeA
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet(sheetName);
for (int i = 0; i < numberOfMergedRow; i++) {
sheet.addMergedRegion(new CellRangeAddress(i, i, 0, numberOfColumns - 1));
sheet.autoSizeColumn(i);
}
XSSFRow row = sheet.createRow(0);
int l = row.getLastCellNum() + 1;
XSSFCell cell = row.createCell((short) l);
XSSFCellStyle cellStyle = workbook.createCellStyle();
Font headerFont = workbook.createFont();
Set<Integer> keyset = data.keySet();
int rownum = 0;
for (Integer key : keyset) {
row = sheet.createRow(rownum++);
Object[] objArr = data.get(key);
int cellnum = 0;
for (Object obj : objArr) {
cell = row.createCell(cellnum++);
if (obj instanceof String)
cell.setCellValue((String) obj);
else if (obj instanceof Integer)
cell.setCellValue((Integer) obj);
else if (obj instanceof Double)
cell.setCellValue((Double) obj);
else if (obj instanceof Number)
cell.setCellValue((Double) obj);
}
cellStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);
cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
/* adding heading style */
cellStyle.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
headerFont.setFontHeightInPoints((short) 12);
cellStyle.setFont(headerFont);
cell.setCellStyle(cellStyle);
xssf工作簿=新的xssf工作簿();
XSSFSheet sheet=workbook.createSheet(sheetName);
for(int i=0;i
如何仅在页眉中设置样式?XSSF工作簿=新建XSSF工作簿();
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet(sheetName);
for (int i = 0; i < numberOfMergedRow; i++) {
sheet.addMergedRegion(new CellRangeAddress(i, i, 0, numberOfColumns - 1));
sheet.autoSizeColumn(i);
}
XSSFRow row = sheet.createRow(0);
int l = row.getLastCellNum() + 1;
XSSFCell cell = row.createCell((short) l);
XSSFCellStyle cellStyle = workbook.createCellStyle();
Font headerFont = workbook.createFont();
cellStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);
cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
/* adding heading style */
cellStyle.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
headerFont.setFontHeightInPoints((short) 12);
cellStyle.setFont(headerFont);
cell.setCellStyle(cellStyle);
Set<Integer> keyset = data.keySet();
int rownum = 0;
for (Integer key : keyset) {
row = sheet.createRow(rownum++);
Object[] objArr = data.get(key);
int cellnum = 0;
for (Object obj : objArr) {
cell = row.createCell(cellnum++);
if (obj instanceof String)
cell.setCellValue((String) obj);
else if (obj instanceof Integer)
cell.setCellValue((Integer) obj);
else if (obj instanceof Double)
cell.setCellValue((Double) obj);
else if (obj instanceof Number)
cell.setCellValue((Double) obj);
}
XSSFSheet sheet=workbook.createSheet(sheetName);
for(int i=0;i
将cellStyle代码移到for循环之外使用两种样式,一种用于标题,另一种用于其他?@Gagravarr,我应该只对标题使用样式,而我只对标题设置样式,问题是我是如何在数据部分列中获得它的?我根本没有样式,在标题部分中没有。