我正在尝试使用以下代码来获取 excel 的所有数据。Excel中的行数为5,列数为20。
PFB 下面的代码
package testRunner;
import java.io.File;
import java.io.FileInputStream;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFSheet;
public class ReadWriteExcel {
public static void main(String args[])
//public static void ReadExcel() throws IOException
{
try
{
//Specify the File path which you want to Create or Write
File src=new File("D:\\eclipse-workspace\\CucumberWithTestNGForSelenium\\PersonalInformation.xlsx");
//Load the file
FileInputStream fis=new FileInputStream(src);
//Load the Workbook
@SuppressWarnings("resource")
XSSFWorkbook wb=new XSSFWorkbook(fis);
//get the sheet which you want to modify or create
XSSFSheet sh1=wb.getSheetAt(0);
//Finding the number of rows
int firstRow=sh1.getFirstRowNum();
int lastRow=sh1.getLastRowNum()+1;
int no_of_rows=lastRow-firstRow;
for(int i=0;i<no_of_rows;i++)
{
//Finding the number of Columns
int no_of_columns=sh1.getRow(i).getLastCellNum();
for(int j=0;j<no_of_columns;j++)
{
System.out.print(" "+ sh1.getRow(i).getCell(j).getStringCellValue()+ " ");
}
System.out.println();
}
}
catch(Exception e)
{
e.getMessage();
}}}
在控制台中,第一行显示所有列,但从第二行开始,它只显示 3-4 列。
PFB
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.poi.openxml4j.util.ZipSecureFile$1 (file:/C:/Users/Mehak/.m2/repository/org/apache/poi/poi-ooxml/3.17/poi-ooxml-3.17.jar) to field java.io.FilterInputStream.in
WARNING: Please consider reporting this to the maintainers of org.apache.poi.openxml4j.util.ZipSecureFile$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Title FirstName LastName EmailValidation Password Date Month Year SignUpCheckbox AddessFirstName AddressLastName Company MainAddress AddressLine2 city State PostalCode Country Mobile AddressAlias
Mr Simon Duffy aduffy@abc.com
Excel 部分在第二张图片上继续:_