fork download
  1. import java.io.BufferedInputStream;
  2. import java.io.FileInputStream;
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.util.Iterator;
  6. import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  7. import org.apache.poi.hssf.usermodel.HSSFCell;
  8. import org.apache.poi.hssf.usermodel.HSSFSheet;
  9. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  10. import org.apache.poi.hssf.usermodel.HSSFRow;
  11.  
  12. public class ReadExcel {
  13.  
  14. public static void main( String [] args ) {
  15. try {
  16.  
  17. InputStream input = new BufferedInputStream(new FileInputStream("C:/Users/zcheung/Desktop/DATA/sample.xls"));
  18. POIFSFileSystem fs = new POIFSFileSystem( input );
  19. HSSFWorkbook wb = new HSSFWorkbook(fs);
  20. HSSFSheet sheet = wb.getSheetAt(0);
  21.  
  22.  
  23. Iterator rows = sheet.rowIterator();
  24. while( rows.hasNext() ) {
  25. HSSFRow row = (HSSFRow) rows.next();
  26. System.out.println("\n");
  27. Iterator cells = row.cellIterator();
  28. while( cells.hasNext() ) {
  29.  
  30. HSSFCell cell = (HSSFCell) cells.next();
  31. if(HSSFCell.CELL_TYPE_NUMERIC==cell.getCellType())
  32. System.out.print( cell.getNumericCellValue()+" " );
  33. else
  34. if(HSSFCell.CELL_TYPE_STRING==cell.getCellType())
  35. System.out.print( cell.getStringCellValue()+" " );
  36. else
  37. if(HSSFCell.CELL_TYPE_BOOLEAN==cell.getCellType())
  38. System.out.print( cell.getBooleanCellValue()+" " );
  39. else
  40. if(HSSFCell.CELL_TYPE_BLANK==cell.getCellType())
  41. System.out.print( "BLANK " );
  42. else
  43. System.out.print("Unknown cell type");
  44.  
  45. }
  46.  
  47.  
  48. }
  49.  
  50.  
  51. } catch ( IOException ex ) {
  52. ex.printStackTrace();
  53. }
  54. }
  55.  
  56. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:12: error: class ReadExcel is public, should be declared in a file named ReadExcel.java
public class ReadExcel {
       ^
Main.java:6: error: package org.apache.poi.poifs.filesystem does not exist
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
                                      ^
Main.java:7: error: package org.apache.poi.hssf.usermodel does not exist
import org.apache.poi.hssf.usermodel.HSSFCell;
                                    ^
Main.java:8: error: package org.apache.poi.hssf.usermodel does not exist
import org.apache.poi.hssf.usermodel.HSSFSheet;
                                    ^
Main.java:9: error: package org.apache.poi.hssf.usermodel does not exist
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
                                    ^
Main.java:10: error: package org.apache.poi.hssf.usermodel does not exist
import org.apache.poi.hssf.usermodel.HSSFRow;
                                    ^
Main.java:18: error: cannot find symbol
            POIFSFileSystem fs = new POIFSFileSystem( input );
            ^
  symbol:   class POIFSFileSystem
  location: class ReadExcel
Main.java:18: error: cannot find symbol
            POIFSFileSystem fs = new POIFSFileSystem( input );
                                     ^
  symbol:   class POIFSFileSystem
  location: class ReadExcel
Main.java:19: error: cannot find symbol
            HSSFWorkbook wb = new HSSFWorkbook(fs);
            ^
  symbol:   class HSSFWorkbook
  location: class ReadExcel
Main.java:19: error: cannot find symbol
            HSSFWorkbook wb = new HSSFWorkbook(fs);
                                  ^
  symbol:   class HSSFWorkbook
  location: class ReadExcel
Main.java:20: error: cannot find symbol
            HSSFSheet sheet = wb.getSheetAt(0);
            ^
  symbol:   class HSSFSheet
  location: class ReadExcel
Main.java:25: error: cannot find symbol
                HSSFRow row = (HSSFRow) rows.next();
                ^
  symbol:   class HSSFRow
  location: class ReadExcel
Main.java:25: error: cannot find symbol
                HSSFRow row = (HSSFRow) rows.next();
                               ^
  symbol:   class HSSFRow
  location: class ReadExcel
Main.java:30: error: cannot find symbol
                    HSSFCell cell = (HSSFCell) cells.next();
                    ^
  symbol:   class HSSFCell
  location: class ReadExcel
Main.java:30: error: cannot find symbol
                    HSSFCell cell = (HSSFCell) cells.next();
                                     ^
  symbol:   class HSSFCell
  location: class ReadExcel
Main.java:31: error: cannot find symbol
                    if(HSSFCell.CELL_TYPE_NUMERIC==cell.getCellType())
                       ^
  symbol:   variable HSSFCell
  location: class ReadExcel
Main.java:34: error: cannot find symbol
                    if(HSSFCell.CELL_TYPE_STRING==cell.getCellType())
                       ^
  symbol:   variable HSSFCell
  location: class ReadExcel
Main.java:37: error: cannot find symbol
                        if(HSSFCell.CELL_TYPE_BOOLEAN==cell.getCellType())
                           ^
  symbol:   variable HSSFCell
  location: class ReadExcel
Main.java:40: error: cannot find symbol
                            if(HSSFCell.CELL_TYPE_BLANK==cell.getCellType())
                               ^
  symbol:   variable HSSFCell
  location: class ReadExcel
19 errors
stdout
Standard output is empty