ASHOK :
i am using the Apache POI to read an xlsx file. i can able to read the Sheet1 data. But when try to read the Sheet2 i am getting the Sheet1 data only.
String strPath = "..\\Test.xlsx";
File excelFile = new File(strPath);
FileInputStream fis = new FileInputStream(excelFile);
// we create an XSSF Workbook object for our XLSX Excel File
XSSFWorkbook workbook = new XSSFWorkbook(fis);
Sheet sheet1= workbook.getSheetAt(0);
Sheet sheet2= workbook.getSheetAt(1);
atomskaze :
When you call getSheetAt(i)
, it returns a XSSFSheet
object, which implements the Sheet
interface under org.apache.poi.ss.usermodel
. Consider the block of code below:
XSSFSheet sheet = workbook.getSheetAt(0);
System.out.println(sheet.getRow(0).getCell(0).getStringCellValue());
sheet = workbook.getSheetAt(1);
System.out.println(sheet.getRow(0).getCell(0).getStringCellValue());
The code above should print the content of cell A1 for the first two sheets on your document. I did it myself with a test file and it worked.
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=358673&siteId=1