java读取excel报错
import java.io.FileInputStream;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ExcelTest {
public static void main(String[] args) {
String fileToBeRead = "F:\test.xlsx";
try {
XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(fileToBeRead)); // 创建对Excel工作簿文件的引用
XSSFSheet sheet = workbook.getSheet("test"); // 创建对工作表的引用
int rows = sheet.getPhysicalNumberOfRows();//获取表格的
for (int r = 0; r < rows; r++) { //循环遍历表格的行
String value = "";
XSSFRow row = sheet.getRow(r); //获取单元格中指定的行对象
if (row != null) {
int cells = row.getPhysicalNumberOfCells();//获取单元格中指定列对象
for (short c = 0; c < cells; c++) { //循环遍历单元格中的列
XSSFCell cell = row.getCell((short) c); //获取指定单元格中的列
if (cell != null) {
if (cell.getCellType() == XSSFCell.CELL_TYPE_STRING) { //判断单元格的值是否为字符串类型
value += cell.getStringCellValue() + ",";
} else if (cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) { //判断单元格的值是否为数字类型