当前难以将DataFormat设置为特定行。
这是我的Excel工作表的外观。我有那四栏。 第1栏应采用DataFormat编号 第2列和第3列应采用DataFormat日期 第4栏可以
public static void createtableRow(Sheet sheet,List<String> EDIROWKeys,int col,CellStyle style,int lastRowNum){
if(sheet == null){
return;
}
int lastRow = lastRowNum;
int newRow = lastRow + 1;
Workbook wb = sheet.getWorkbook();
SimpleDateFormat format = new SimpleDateFormat();
CreationHelper helper = wb.getcreationHelper();
org.apache.poi.ss.usermodel.DataFormat date = wb.createDataFormat();
XSSFRow row = (XSSFRow) sheet.createRow(newRow);
if(row == null){
return;
}
int startCol = col;
for(String string : EDIROWKeys){
XSSFCell cell = row.createCell(startCol);
FOe.getFOPSessionContext().getDbContext().out().println(string);
if(style != null){
cell.setCellStyle(style);
}else {
XSSFWorkbook wbx = (XSSFWorkbook) sheet.getWorkbook();
XSSFDataFormat dataformat = wbx.createDataFormat();
XSSFCellStyle cs = wbx.createCellStyle();
if(startCol == 1){
cs.setDataFormat(dataformat.getFormat("#"));
}
cell.setCellStyle(cs);
}
cell.setCellValue(string);
startCol++;
}
return;
}
这是我用来创建行和列的方法 https://poi.apache.org/apidocs/dev/org/apache/poi/ss/usermodel/BuiltinFormats.html 这是我从中获取DataFormats的资源。 我还尝试将具有HssfDataformat的DataFormats应用于单元格-也没有成功。
我感谢任何有帮助的意见:)
通过使用setCellValue(Double); ...
if(string.matches("\\d+")){
cell.setCellValue(Double.valueOf(string));
startCol++;
continue;
}