可能是您正在使用的
.xls
文件,并将创建此类型的文件。但它支持的栏目不多
但是如果你使用更新的格式
支持1048576行和16384列
支持相应行和列的MS Excel
+-----------------+-----------+--------------+---------------------+
| | Max. Rows | Max. Columns | Max. Cols by letter |
+-----------------+-----------+--------------+---------------------+
| Excel 365* | 1,048,576 | 16,384 | XFD |
| Excel 2013 | 1,048,576 | 16,384 | XFD |
| Excel 2010 | 1,048,576 | 16,384 | XFD |
| Excel 2007 | 1,048,576 | 16,384 | XFD |
| Excel 2003 | 65,536 | 256 | IV |
| Excel 2002 (XP) | 65,536 | 256 | IV |
| Excel 2000 | 65,536 | 256 | IV |
| Excel 97 | 65,536 | 256 | IV |
| Excel 95 | 16,384 | 256 | IV |
| Excel 5 | 16,384 | 256 | IV |
+-----------------+-----------+--------------+---------------------+
但这里你用的是
XSSF
这意味着你的文件在
格式,以便支持此限制。但是如果你的文件在
.xls
格式,则不支持此限制。
如果你使用
你可以试试这个代码。也许对你有帮助。
private static void writeData() throws IOException {
Workbook workbook = new XSSFWorkbook();
XSSFSheet sheet = (XSSFSheet) workbook.createSheet();
int r = 0;
for (int i=0;i<2;i++) {
Row row = sheet.createRow(r++);
int column = 0;
for (int j =0;j<2;j++) {
XSSFCell cell = (XSSFCell) row.createCell(column++);
if (r == 1 || column == 1) cell.setCellValue(i);
else if (column == 2) {
cell.setCellFormula("OFFSET(IU220,0,1)");
}
}
}
FileOutputStream fileOut = new FileOutputStream("stackProblem.xlsx");
workbook.write(fileOut);
workbook.close();
}
evaluator.evaluateInCell(cell);
不支持超过255列。你可能有用
evaluator.evaluate(cell);
试试这个
public static void main(String[] args) throws IOException {
writeData();
}
private static void writeData() throws IOException {
Workbook workbook = new XSSFWorkbook();
XSSFSheet sheet = (XSSFSheet) workbook.createSheet();
XSSFRow row218 = sheet.createRow(218);
XSSFCell vv2180 = (XSSFCell) row218.createCell(255);
vv2180.setCellValue(50);
XSSFCell vv2181 = (XSSFCell) row218.createCell(256);
vv2181.setCellValue(69);
XSSFRow row219 = sheet.createRow(219);
XSSFCell vv0 = (XSSFCell) row219.createCell(255);
vv0.setCellValue(40);
XSSFCell vv = (XSSFCell) row219.createCell(256);
vv.setCellValue(70);
XSSFRow row220 = sheet.createRow(220);
XSSFCell vv2200 = (XSSFCell) row220.createCell(255);
vv2200.setCellValue(30);
XSSFCell vv220 = (XSSFCell) row220.createCell(256);
vv220.setCellValue(20);
XSSFCell cell = sheet.createRow(1).createCell(1);
cell.setCellFormula("OFFSET(IV220,0,1)");
XSSFFormulaEvaluator evaluator =
(XSSFFormulaEvaluator) workbook.getCreationHelper().createFormulaEvaluator();
evaluator.evaluate(cell);
FileOutputStream fileOut = new FileOutputStream("stackProblem.xlsx");
workbook.write(fileOut);
workbook.close();
}
poi库的良好参考:
apche poi HSSF vs XSSF