旧版readStringLine备份
程序员成长之旅 · 程序员成长之旅/Java学习/源码 · 423 字
String[] readStringLine(int sheetIndex, int rowIndex){
String[] data = new String[200];
String[] cleanData;
try {
if (sheetIndex<0||sheetIndex>numberOfSheets){
throw new ValueException("未找到您想要找的sheet编号:["+sheetIndex+"]");
}
sheet = workbook.getSheetAt(sheetIndex-1);
numberOfRow = sheet.getLastRowNum();
if (rowIndex<0||rowIndex>numberOfRow){
throw new ValueException("未找到您想要找的row编号:["+rowIndex+"]");
}
row = sheet.getRow(rowIndex-1);
numberOfCell = row.getLastCellNum();
if (numberOfCell==0){
return null;
}
for (int i=0;i<numberOfCell;i++){
cell = row.getCell(i);
cell.setCellType(CellType.STRING);
if (cell.getStringCellValue()!=null){
data[i]=cell.getStringCellValue();
}
else {
data[i]="[NoDate]";
}
}
if (data!=null){
for (int i=0;i<data.length;i++){
if (data[i]==null){
cleanData = new String[i];
for(int j=0;j<i;j++){
cleanData[j]=data[j];
}
data = null;
return cleanData;
}
}
}else {
throw new ValueException("数组为空");
}
for (int i=0;i<data.length;i++){
if (data==null){
throw new ValueException("数组为空");
}
if (data[i]==null){
cleanData = new String[i];
for(int j=0;j<i;j++){
cleanData[j]=data[j];
}
data = null;
return cleanData;
}
}
return null;
}
catch (Exception e){
System.out.println("在readStringLine方法内发生错误:["+e.getClass()+e.getCause()+e.getMessage()+"]");
return null;
}
}
String[] readStringLine(int sheetIndex, int rowIndex,int rowEnd){
String[] data = new String[200];
String[] cleanData;
try {
if (sheetIndex<0||sheetIndex>numberOfSheets){
throw new ValueException("未找到您想要找的sheet编号:["+sheetIndex+"]");
}
sheet = workbook.getSheetAt(sheetIndex-1);
numberOfRow = sheet.getLastRowNum();
if (rowIndex<0||rowIndex>numberOfRow){
throw new ValueException("未找到您想要找的row编号:["+rowIndex+"]");
}
row = sheet.getRow(rowIndex-1);
numberOfCell = row.getLastCellNum();
if (numberOfCell==0){
return null;
}
for (int i=0;i<numberOfCell;i++){
cell = row.getCell(i);
cell.setCellType(CellType.STRING);
if (cell.getStringCellValue()!=null){
data[i]=cell.getStringCellValue();
}
else {
data[i]="[NoDate]";
}
}
if (data!=null){
for (int i=0;i<data.length;i++){
if (data[i]==null){
cleanData = new String[i];
for(int j=0;j<i;j++){
cleanData[j]=data[j];
}
data = null;
return cleanData;
}
}
}else {
throw new ValueException("数组为空");
}
for (int i=0;i<data.length;i++){
if (data==null){
throw new ValueException("数组为空");
}
if (data[i]==null){
cleanData = new String[i];
for(int j=0;j<i;j++){
cleanData[j]=data[j];
}
data = null;
return cleanData;
}
}
return null;
}
catch (Exception e){
System.out.println("在readStringLine方法内发生错误:["+e.getClass()+e.getCause()+e.getMessage()+"]");
return null;
}
}