Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
  2. import org.apache.poi.ss.usermodel.*;
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.util.Iterator;
  6.  
  7. public class ExcelReader {
  8. public static final String XLSX_FILE_PATH = "./arquivo-excel.xlsx";
  9.  
  10. public static void main(String[] args) throws IOException, InvalidFormatException {
  11.  
  12. //Criando um Workbook de Uma Arquivo Excel (.xlsx ou .xls)
  13. Workbook workbook = WorkbookFactory.create(new File(XLSX_FILE_PATH));
  14.  
  15. //Visualizando Todas as Sheets presentes na planilha
  16. for(Sheet sheet: workbook) {
  17. System.out.println("=> " + sheet.getSheetName());
  18. }
  19.  
  20.  
  21. // Visualizando os valores das células da primeira aba da planilha
  22. Sheet sheet = workbook.getSheetAt(0);
  23.  
  24. for (Row row: sheet) {
  25. for(Cell cell: row) {
  26. String cellValue = dataFormatter.formatCellValue(cell);
  27. System.out.print(cellValue + "t");
  28. }
  29. System.out.println();
  30. }
  31.  
  32. workbook.close();
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement