当我下载 Excel 时,我得到格式为 Numbers 的单元格,我需要在所有单元格中设置文本格式。
try {
XSSFSheet sheet = workbook.createSheet(eyelash);
XSSFFont font = workbook.createFont();
font.setColor(HSSFColor.WHITE.index);
XSSFCellStyle style = workbook.createCellStyle();
style.setFont(font);
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setFillForegroundColor(HSSFColor.RED.index);
String[] header = { "name","surname"};
XSSFRow rowhead = sheet.createRow((short) 0);
XSSFCell cell;
int cellnum = 0;
for (int i = 0; i < header.length; i++) {
cell = rowhead.createCell(cellnum);
cell.setCellValue(header[i]);
cell.setCellStyle(style);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
cellnum++;
}
if (data) {
int myRowData = 1;
XSSFRow row = sheet.createRow((short) myRowData);
ArrayList<GasNomination> list = this.select();
for (int i = 0; i < list.size(); i++) {
row.createCell(0).setCellValue(list.get(i).name());
row.createCell(1).setCellValue(list.get(i).surname());
myRowData++;
row = sheet.createRow((short) myRowData);
}
}
} catch (Exception ex) {
}
我试过 cell.setCellType(XSSFCell.CELL_TYPE_STRING); 但是当我打开 Excel 时,我看到 formatcell 类型为 numeric ...
神不在的星期二
相关分类