`
grape927
  • 浏览: 73656 次
  • 性别: Icon_minigender_2
  • 来自: 深圳
社区版块
存档分类
最新评论

jxl读取excel

    博客分类:
  • JAVA
 
阅读更多
public class TestJXLRead {
    public static void main(String[] args) throws Exception {
        TestJXLRead testJXL = new TestJXLRead(); 
        testJXL.readExcelFile("C:/testExcel.xls");
    }
    public static void readExcelFile(String excelFileName) throws Exception{
        File excelFile = new File(excelFileName);
        
        int excelFileSize = (int) excelFile.length();

        WorkbookSettings workbookSettings = new WorkbookSettings();
        //设定禁止System.gc()的操作
        workbookSettings.setGCDisabled(true);
        
 		   //设定文件初始化大小为Excel文件大小+1,此处加一必不可少!!!不要遗忘!!!
        //从而避免创建的数组对象过大;或过小导致数组频繁扩展,产生大量垃圾
        workbookSettings.setInitialFileSize(excelFileSize+1);

        //我们一定要确保把定制的workbookSettings对象作为Workbook创建的制定属性。
        Workbook workbook = Workbook.getWorkbook(excelFile, workbookSettings);

        workbook.close();
    	}
}

 

String excelFileName = "test.xsl";
File excelFile = new File(excelFileName);

WorkbookSettings workbookSettings = new WorkbookSettings();
//设定禁止System.gc()的操作
workbookSettings.setGCDisabled(true);

//设定使用临时文件操作的方式,来代替内存byte[] data Excel文件的创建,减少内存的消耗
 	workbookSettings.setUseTemporaryFileDuringWrite(true);

//用来设定临时文件的目录,如果此项属性没有设置,将会在操作系统默认临时目录中创建临时文件
 	workbookSettings.setTemporaryFileDuringWriteDirectory(new File("c:/tmp"));
 
	//我们一定要确保把定制的workbookSettings对象作为Workbook创建的制定属性。
 	WritableWorkbook tWorkbook = Workbook.createWorkbook(excelFile, workbookSettings);

 	WritableSheet tBatch = tWorkbook.createSheet("Your First Sheet",0);

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics