Java操作xls

作者在 2016-12-19 15:55:25 发布以下内容
package fuck;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;  
import jxl.Cell;   
import jxl.CellType;   
import jxl.Sheet;   
import jxl.Workbook;   
import jxl.write.Label; 

public class ExcelOperater    
{   
  
    public static void main(String[] args)    
    {   
  
        jxl.Workbook readwb = null;   
        try    
        {   
  
            //构建Workbook对象, 只读Workbook对象   
  
            //直接从本地文件创建Workbook   
  
            InputStream instream = new FileInputStream("D:/input_data.xls");   //这个jar包只支持xls的文件
  
            readwb = Workbook.getWorkbook(instream);   
            //Sheet的下标是从0开始   
  
            //获取第一张Sheet表   
  
            Sheet readsheet = readwb.getSheet(0);   
  
            //获取Sheet表中所包含的总列数   
  
            int rsColumns = readsheet.getColumns();   
  
            //获取Sheet表中所包含的总行数   
  
            int rsRows = readsheet.getRows();   
  
            //获取指定单元格的对象引用   
  
            for (int i = 0; i < rsRows; i++)   
            {   
                for (int j = 0; j < rsColumns; j++)   
                {   
                    Cell cell = readsheet.getCell(j, i);   
                    System.out.print(cell.getContents() + " ");   
                }   
                System.out.println();   
            }   
        } 
	    catch (Exception e) 
	       {   
	            e.printStackTrace();   
	       } 
	    finally 
	       {   
	            readwb.close();   
	       }
    }   
}   
JAVA | 阅读 1492 次
文章评论,共0条
游客请输入验证码
浏览2354337次