用apache.poi读excel

用apache.poi读excel

public   static   void  main(String[] args)  throws  Exception  {
        POIFSFileSystem pfs 
= new POIFSFileSystem(new FileInputStream("D:\\test_xls.xls"));             
        HSSFWorkbook hwk 
= new HSSFWorkbook(pfs);
        HSSFSheet sheet 
= hwk.getSheet("Sheet1");
        
try{
            
int lrn = sheet.getLastRowNum();
            
for(int r = 0;r<lrn;r++){
                Row row 
= sheet.getRow(r);                
                
int lcn = row.getLastCellNum();
                
for(int c = 0;c<lcn;c++){            
                    
if(row.getCell(c)==null)
                        System.out.println(
"R=" + r + ",C=" + c + ":NULL");
                    
else
                        System.out.println(
"R=" + r + ",C=" + c + ":" + row.getCell(c).toString());
                }

            }

        }
catch(Exception e){
            e.printStackTrace();
        }

    }

你可能感兴趣的:(用apache.poi读excel)