我有两张excel表格。目前我的需求是,我需要对excel列值执行一些操作,并将该值写入上面提到的一个excel表中。下面我提到了我的代码,但它在row3行抛出了错误。
File file=new File("D:\\Udaya files\\D-udaya files\\desktop_udaya files\\markting\\Gartner Dashboard\\Gartner Dashboard 28-12-2018\\AdminReportHTCoverPage.xlsx");
XSSFWorkbook wb=new XSSFWorkbook(file);
XSSFSheet sheet=wb.getSheetAt(1);
XSSFRow row=null;
int rowcount=sheet.getLastRowNum()+1;
File dashboard=new File("D:\\Udaya files\\D-udaya files\\desktop_udaya files\\markting\\Gartner Dashboard\\Gartner Dashboard 28-12-2018\\Weekly Dashboard_Garner users FY 18.xlsx");
XSSFWorkbook wb1=new XSSFWorkbook(dashboard);
XSSFSheet sheet1=wb.getSheet("December 28th");
XSSFRow row1=null;
int dashcount=sheet.getLastRowNum()+1;
int free=0;
int paid=0;
int paid_count=0;
for(int i=0;i<dashcount;i++)
{
String name=sheet1.getRow(i).getCell(1).getStringCellValue();
for(int j=0;j<rowcount;j++)
{
String firstname=sheet.getRow(i).getCell(1).getStringCellValue();
if(name.equals(firstname))
{
if(sheet.getRow(i).getCell(3).getStringCellValue()== "0" || sheet.getRow(i).getCell(3).getStringCellValue()== "")
{
free=free+1;
}
else
{
int value= (int) sheet.getRow(i).getCell(3).getNumericCellValue();
paid=paid+value;
paid_count=paid_count+1;
}
}
Row row3=sheet1.getRow(i);
row3.getCell(2).setCellValue(free);
row3.getCell(3).setCellValue(paid_count);
row3.getCell(4).setCellValue(paid);
}
}对于sheet1文件,getLastRowNum()不能正常工作。它没有显示正确的数字。
发布于 2019-01-09 01:07:21
XSSFSheet.getLastRowNum()是从零开始的。这就是为什么如果你得到的结果是row number - 1,你会认为它并不代表正确的数字。
如果Excel表格中的行号为5,则XSSFSheet.getLastRowNum()将返回4。
您还可以在下面的链接中找到很好的示例;http://poi.apache.org/components/spreadsheet/quick-guide.html
你在你的代码中遇到了什么样的错误?
https://stackoverflow.com/questions/54091727
复制相似问题