使用Java从xlsx文件读取数据

问题描述

这是从Java中的Excel文件读取数据的代码,我的switch case语句有问题,

重复的案卷标签
枚举开关的大小写标签必须是枚举常量的非限定名称”。

请告诉我,这是什么问题?

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.hssfSheet;
import org.apache.poi.hssf.usermodel.hssfWorkbook;
import static org.apache.poi.hssf.usermodel.headerfooter.file;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
public class ReadExcelFileDemo {
  public static void main(String args[]) throws IOException {
    //obtaining input bytes from a file  
    FileInputStream fis = new FileInputStream(new File("C:\\Users\\DGSN\\Desktop\\test.xlsx"));
    //creating workbook instance that refers to .xls file  
    hssfWorkbook wb = new hssfWorkbook(fis);
    //creating a Sheet object to retrieve the object  
    hssfSheet sheet = wb.getSheetAt(0);
    //evaluating cell type   
    FormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
    System.out.println("The given file is");
    for (Row row: sheet)
    //iteration over row using for each loop  
    {
      for (Cell cell: row) //iteration over cell using for each loop  
      {
        switch (formulaEvaluator.evaluateInCell(cell).getCellType()) {
        case Cell.CELL_TYPE_NUMERIC:
          //field that represents numeric cell type  
          //getting the value of the cell as a number  
          System.out.print(cell.getNumericCellValue() + "\t\t");
          break;
        case Cell.CELL_TYPE_STRING:
          //field that represents string cell type  
          //getting the value of the cell as a string  
          System.out.print(cell.getStringCellValue() + "\t\t");
          break;
        }
      }
      System.out.println();
    }
  }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)