afunms

My Software,My Dream—Forge a more perfect NMS product.

用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();
        }

    }

posted on 2011-10-09 16:53 afunms 阅读(257) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

My Links

News

留言簿(18)

随笔档案

相册

搜索

最新评论

阅读排行榜