欢迎来到天天文库
浏览记录
ID:1990430
大小:102.50 KB
页数:8页
时间:2017-11-14
《poi操作excel实例》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、importjava.io.BufferedInputStream;importjava.io.File;importjava.io.FileInputStream;importjava.io.FileNotFoundException;importjava.io.FileOutputStream;importjava.io.IOException;importjava.text.DecimalFormat;importjava.text.SimpleDateFormat;importjava.u
2、til.ArrayList;importjava.util.Arrays;importjava.util.Date;importjava.util.List;importorg.apache.poi.hssf.usermodel.HSSFCell;importorg.apache.poi.hssf.usermodel.HSSFCellStyle;importorg.apache.poi.hssf.usermodel.HSSFDateUtil;importorg.apache.poi.hssf.us
3、ermodel.HSSFRow;importorg.apache.poi.hssf.usermodel.HSSFSheet;importorg.apache.poi.hssf.usermodel.HSSFWorkbook;importorg.apache.poi.poifs.filesystem.POIFSFileSystem;publicclassEditExcel{publicstaticvoidmain(String[]args){Stringpath="f://#usertemple.xl
4、s";//文件路径try{Filefiles=newFile(path);Listlist=getDataList(files);//读取if(list!=null&&list.size()>0){for(String[]str:list){for(inti=0;i5、xceptione){e.printStackTrace();}}/***读取EXCEL**@paramfirstrow*从第几行开始读取*@return读取后返回数组*/publicstaticString[][]getData(Filefile,intfirstrow)throwsFileNotFoundException,IOException{Listresult=newArrayList();introwSize=0;BufferedInputSt6、reamin=newBufferedInputStream(newFileInputStream(file));POIFSFileSystemfs=newPOIFSFileSystem(in);HSSFWorkbookwb=newHSSFWorkbook(fs);HSSFCellcell=null;for(intsheetIndex=0;sheetIndex7、dex);for(introwIndex=firstrow;rowIndex<=st.getLastRowNum();rowIndex++){HSSFRowrow=st.getRow(rowIndex);if(row==null){continue;}inttempRowSize=row.getLastCellNum()+1;if(tempRowSize>rowSize){rowSize=tempRowSize;}String[]values=newString[rowSize];Arrays.f8、ill(values,"");booleanhasValue=false;for(shortcolumnIndex=0;columnIndex<=row.getLastCellNum();columnIndex++){Stringvalue="";cell=row.getCell(columnIndex);if(cell!=null){switch(cell.getCellType()){caseHSSFCell.CELL_TYPE_STRING://读取的格式为字符串value=
5、xceptione){e.printStackTrace();}}/***读取EXCEL**@paramfirstrow*从第几行开始读取*@return读取后返回数组*/publicstaticString[][]getData(Filefile,intfirstrow)throwsFileNotFoundException,IOException{Listresult=newArrayList();introwSize=0;BufferedInputSt
6、reamin=newBufferedInputStream(newFileInputStream(file));POIFSFileSystemfs=newPOIFSFileSystem(in);HSSFWorkbookwb=newHSSFWorkbook(fs);HSSFCellcell=null;for(intsheetIndex=0;sheetIndex7、dex);for(introwIndex=firstrow;rowIndex<=st.getLastRowNum();rowIndex++){HSSFRowrow=st.getRow(rowIndex);if(row==null){continue;}inttempRowSize=row.getLastCellNum()+1;if(tempRowSize>rowSize){rowSize=tempRowSize;}String[]values=newString[rowSize];Arrays.f8、ill(values,"");booleanhasValue=false;for(shortcolumnIndex=0;columnIndex<=row.getLastCellNum();columnIndex++){Stringvalue="";cell=row.getCell(columnIndex);if(cell!=null){switch(cell.getCellType()){caseHSSFCell.CELL_TYPE_STRING://读取的格式为字符串value=
7、dex);for(introwIndex=firstrow;rowIndex<=st.getLastRowNum();rowIndex++){HSSFRowrow=st.getRow(rowIndex);if(row==null){continue;}inttempRowSize=row.getLastCellNum()+1;if(tempRowSize>rowSize){rowSize=tempRowSize;}String[]values=newString[rowSize];Arrays.f
8、ill(values,"");booleanhasValue=false;for(shortcolumnIndex=0;columnIndex<=row.getLastCellNum();columnIndex++){Stringvalue="";cell=row.getCell(columnIndex);if(cell!=null){switch(cell.getCellType()){caseHSSFCell.CELL_TYPE_STRING://读取的格式为字符串value=
此文档下载收益归作者所有