微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用Java从xlsx文件读取数据

如何解决使用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 举报,一经查实,本站将立刻删除。