问题描述:
java.lang.IllegalArgumentException: Minimum column number is 0
问题分析:
1、合并单元格初始化CellRangeAddress时,参数<0。
//开始行号
int startRowIndex =0;
//结束行号
int endRowIndex = 0;
//开始列号
int startColumnIndex = -1;
//结束列号
int endColumnIndex = 0;
CellRangeAddress cellRangeAddress = new CellRangeAddress(startRowIndex, endRowIndex, startColumnIndex, endColumnIndex);
解决办法:
行号和列号>0时初始化CellRangeAddress,行号和列号<0时不初始化CellRangeAddress。
//开始行号
int startRowIndex =0;
//结束行号
int endRowIndex = 0;
//开始列号
int startColumnIndex = -1;
//结束列号
int endColumnIndex = 0;
//判断是否行号和列号非法(<0)
if (startColumnIndex > 0 && endColumnIndex > 0 && startRowIndex > 0 && endRowIndex > 0 ) {
CellRangeAddress cellRangeAddress = new CellRangeAddress(startRowIndex, endRowIndex, startColumnIndex, endColumnIndex);
}