0

This is code to read data from an Excel file in Java and I have a problem with switch case statement which is:

duplicate case label
an enum switch case label must be unqualified name of enumeration constant".

Please tell me, what's the problem here?

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();
    }
  }
}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

0 Answers0