title: How to read an excel file in spring boot
body: <p>i am new to springboot and i have moderate experience in java, i was given a task to import an excel data in batches, i followed tutorials online but i am not getting any data when i run it out on postman. i don't know if i will have to create a service for the excel data.
  Below is my code</p>
  <p>Data Controller</p>
  <pre><code>import org.apache.poi.ss.usermodel.*;
  import org.apache.poi.xssf.usermodel.XSSFRow;
  import org.apache.poi.xssf.usermodel.XSSFSheet;
  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  import org.springframework.http.HttpStatus;
  import org.springframework.http.MediaType;
  import org.springframework.http.ResponseEntity;
  import org.springframework.web.bind.annotation.*;
  import org.springframework.web.multipart.MultipartFile;
  import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
  import org.apache.poi.ss.usermodel .*;
  import java.io.File;
  import java.io.IOException;
  import java.util.Iterator;
  
  import java.io.*;
  import java.util.*;
  
  
  @RestController
  @RequestMapping(&quot;datafile&quot;)
  public class DataController {
  
    @RequestMapping(value = &quot;getdata&quot;, method = RequestMethod.GET)
      public void createBus() throws IOException {
  
  
           final String SAMPLE_XLSX_FILE_PATH = &quot;C:\\project\\transita\\src\\main\\resources\\tran.xlsx&quot;;
  
  
          // Creating a Workbook from an Excel file (.xls or .xlsx)
          Workbook workbook;
  
          {
              try {
                  workbook = WorkbookFactory.create(new File(SAMPLE_XLSX_FILE_PATH));
  
  
  
              // Retrieving the number of sheets in the Workbook
              System.out.println(&quot;Workbook has &quot; + workbook.getNumberOfSheets() + &quot; Sheets : &quot;);
  
              Iterator&lt;Sheet&gt; sheetIterator = workbook.sheetIterator();
              System.out.println(&quot;Retrieving Sheets using Iterator&quot;);
              while (sheetIterator.hasNext()) {
                  Sheet sheet = sheetIterator.next();
                  System.out.println(&quot;=&gt; &quot; + sheet.getSheetName());
  
                  sheet = workbook.getSheetAt(0);
  
                  // Create a DataFormatter to format and get each cell's value as String
                  DataFormatter dataFormatter = new DataFormatter();
  
                  // 1. You can obtain a rowIterator and columnIterator and iterate over them
                  System.out.println(&quot;\n\nIterating over Rows and Columns using Iterator\n&quot;);
                  Iterator&lt;Row&gt; rowIterator = sheet.rowIterator();
                  while (rowIterator.hasNext()) {
                      Row row = rowIterator.next();
  
                      // Now let's iterate over the columns of the current row
                      Iterator&lt;Cell&gt; cellIterator = row.cellIterator();
  
                      while (cellIterator.hasNext()) {
                          Cell cell = cellIterator.next();
                          String cellValue = dataFormatter.formatCellValue(cell);
                          System.out.print(cellValue + &quot;\t&quot;);
                      }
                      System.out.println();
                  }
  
                  try {
                      workbook.close();
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
  
      }
  
  }
  </code></pre>