文件导入导出必须代码
Exportexcel.java
/*** Copyright © 2012-2014 <a href = "https://github.com/thinkgem/jeesite"> jeesite </a> 모든 권리 보유. */package com.thinkgem.jeesite.common.utils.excel; import java.io.filenotfoundexception; import java.io.fileoutputStream; import java.io.ioexception; import java.io.outputStream; import java.lang.reflect.field; import java.lang.reflect.method; import java.text.decmimalformat; import java.util.collession; java.util.comparator; import java.util.date; import java.util.hashmap; import java.util.linkedhashmap; import java.util.list; import java.util.map; import javax.servlet.http.httpservletresponse; import org.apache.commons.lang3.stringutils; import org.apache.poi.ss.usermodel.cell; import org.apache.s.usermodel.cellstyle; import org.apache.poi.ss.usermodel.com; import org.apache.poi.ss.smodel org.apache.poi.ss.usermodel.font; import org.apache.poi.ss.usermodel.indexedcolors; import org.apache.poi.ss.usermodel.row; import org.apache.poi.ss.s.usermodel.sheet; import org.apache.poi.ss.usermodel org.apache.poi.ss.util.cellrangeaddress; import org.apache.poi.xssf.streaming.sxssfworkbook; import org.apache.poi.xssf.usermodel.xssfclientAnchor; import org.apache.poi.xssf.usermodel.xssprichodtring; org.slf4j.logger; import org.slf4j.loggerfactory; 가져 오기 com.google.common.collect.lists; import com.thinkgem.jeesite.common.utils.dateutils; import com.thinkgem.jeesite.common.utils.encodes; import com.thinkgem.jeesite.common.util.reflestsions; 가져 오기; com.thinkgem.jeesite.common.util.excel.annotation.excelfield; import com.thinkgem.jeesite.modules.sys.utils.dictutils; /** * 导出 导出 acel 文件 文件 (导出“XLSX”格式 格式 格式 格式 格式 格式 格式 支持大数据量导出 @see org.apache.poi.ss.spreadsheetversion ← * @Author ThinkGem * @version 2013-04-21 */public class exportexcel {private static logger log = loggerfactory.getLogger. / ** * 工作薄对象 */ private sxssfworkbook wb; / ** * 工作表对象 */ 개인 시트 시트; / ** * 样式列表 */ 개인지도 <문자열, CellStyle> 스타일; / ** * 当前行号 */ private int rownum; /** * 注解列表 (object [] {excelfield, field/method}) */list <object []> annotationList = lists.newarrayList (); / ** * MAP */ LINKEDHASHMAP <String, String> FieldMap; Hashmap <String, String> DictTypes; / ** * 构造函数 * @param 제목 表格标题 表格标题 表格标题 表格标题, 传“空值”, 表示无标题 * @param cls 实体对象, 通过 anotation.exportfield 获取标题 */ public exportexcel (문자열 제목, class <?> cls) {this (title, cls, 1); } / ** * * * @param title 表格标题 表格标题 表格标题 表格标题, 传“空值”<空值 * @param fieldmap f, 获取要导出的字段和字段标题 * / public exportexcel (문자열 제목, linkedhashmap <string, string> fieldmap) {this.fieldMap = fieldMap; DictTypes = new Hashmap <String, String> (); // int colunm = 0; 목록 <string> headerlist = lists.newarraylist (); for (문자열 키 : fieldmap.keyset ()) {문자열 t = fieldmap.get (키); hashmap <string, string> map = com.thinkgem.jeesite.common.utils.stringutils.tomap ( ";", "=", false); if (map.get ( "name")! = null) {t = map.get ( "name"); } if (map.get ( "dicttype")! = null) {dicttypes.put ( ""+(colunm), map.get ( "dicttype")); } colunm ++; headerlist.add (t); } 초기화 (제목, 헤더리스트); } / ** * * * @param title 表格标题 表格标题, 传“空值”,“空值”, 表示无标题 * @param cls 实体对象 实体对象, 通过 anotation.exportfield 获取标题 * @param type 导出类型 导出类型 导出类型 导出类型 导出类型 导出类型 导出类型 导出类型 导出类型 导出类型 导出类型 导出类型 导出类型 导出类型 导出类型 导出类型 导出类型 导出类型 导出类型 导出类型 ay ■ : 导出模板) * @param Groups (문자열 제목, 클래스 <?> int 유형 ...) {// get antation field. cls.getDeclaredFields (); for (field f : fs) {excelfield ef = f.getAnnotation (xcelfield.class); if (ef! = null && (ef.type () == 0 || ef.type () == type)) {if (groups! = null && groups.length> 0) {boolean ingroup = false; for (int g : groups) {if (ingroup) {break; } for (int efg : ef.groups ()) {if (g == efg) {ingroup = true; AnnotationList.add (new Object [] {ef, f}); 부서지다; }}}} else {AnnotationList.add (new Object [] {ef, f}); }}} // get get annotation method method [] ms = cls.getDeclaredMethods (); for (method m : ms) {excelfield ef = m.getAntotation (xcelfield.class); if (ef! = null && (ef.type () == 0 || ef.type () == type)) {if (groups! = null && groups.length> 0) {boolean ingroup = false; for (int g : groups) {if (ingroup) {break; } for (int efg : ef.groups ()) {if (g == efg) {ingroup = true; AnnotationList.add (new Object [] {ef, m}); 부서지다; }}}} else {AnnotationList.add (new Object [] {ef, m}); }}} // Field Sorting Collections.SORT (AnnotationList, New Comparator <Object []> () {public int compart (object [] o1, object [] o2) {return new Integer (((excelfield) O1 [0]). Sort ()) // 초기화 목록 <string> headerlist = lists.newarrayList (); for (object [] os : annotationList) {string t = ((excelfield) os [0]). title (); // 如果是导出, 如果是导出 if (type == 1) {string [] ss = stringUtils.split (t, "**", 2); if (ss.length == 2) {t = ss [0]; }} headerlist.add (t); } 초기화 (제목, 헤더리스트); } / ** * * * @param title 表格标题 表格标题 表格标题 表格标题 表格标题 表格标题 表格标题 表格标题 表格标题 表格标题 空值 空值 * @param 헤더 表头数组 * / public exportexcel (문자열 제목, 문자열 [] 헤더) {초기화 (title, lists.newarraylist (headers)); } / ** * * * @param title 表格标题 表格标题 表格标题 表格标题, 传“空值”, 表示无标题 * @param headerlist 表头列表 * / public exportexcel (문자열 제목, list <string> headerlist) {초기화 (제목, headerlist); } / ** * * * @param 제목 表格标题 表格标题 表格标题, 传 "空值", 空值 * @param headerlist 表头列表 * / private void initialize (문자열 제목, list <string> headerlist) {this.wb = new sxssfworkbook (500); this.sheet = wb.createsheet ( "내보내기"); this.styles = createstylles (wb); // 제목을 생성 if (stringUtils.isnotblank (title)) {row titlerow = sheet.createrow (rownum ++); titlerow.setheightinpoints (30); 셀 titlecell = titlerow.createcell (0); titleCell.setCellStyle (Styles.get ( "title")); titleCell.setCellValue (제목); SETER.ADDMERGEDERGION (New CellRangeAddress (titlerow.getRownum (), titlerow.getRownum (), titlerow.getRownum (), headerlist.size () -1)); } // 헤더를 만들면 (headerlist == null) {새 runtimeexception 던지기 ( "headerlist not null!"); } row headerrow = sheet.createrow (rownum ++); Headerrow.setheightinpoints (16); for (int i = 0; i <headerlist.size (); i ++) {cell cell = headerrow.createcell (i); Cell.setCellStyle (Styles.get ( "Header")); 문자열 [] ss = stringUtils.split (headerlist.get (i), "**", 2); if (ss.length == 2) {cell.setCellValue (ss [0]); 의견 댓글 = this.sheet.createdRawingPatriach (). CreateCellComment (New XSSFClientAnchor (0, 0, 0, 0, (짧은) 3, 3, (Short) 5, 6)); comment.SetString (New XSSFrichTexTString (SS [1])); Cell.setCellComment (댓글); } else {cell.setCellValue (headerList.get (i)); } sheet.autoSecolumn (i); } for (int i = 0; i <headerlist.size (); i ++) {int colwidth = sheet.getColumnWidth (i)*2; 시트 .setColumnWidth (i, colwidth <3000? 3000 : colwidth); } log.debug ( "성공 초기화"); } / ** * * * @param wb 工作薄对象 * @return 样式列表 * / private map <string, cellstyle> createStyles (Workbook WB) {map <String, CellStyle> 스타일 = new Hashmap <String, CellStyle> (); CellStyle Style = WB.CreateCellStyle (); style.setalignment (cellstyle.align_center); style.setverticalalignment (cellstyle.vertical_center); font titlefont = wb.createfont (); TitleFont.SetFontName ( "Arial"); TitleFont.SetFonTheightInPoints ((짧은) 16); TitleFont.setBoldweight (font.boldweight_bold); style.setfont (TitleFont); Styles.put ( "제목", 스타일); 스타일 = wb.createcellstyle (); style.setverticalalignment (cellstyle.vertical_center); style.setborderright (cellstyle.border_thin); style.setrightbordercolor (indexedColors.grey_50_percent.getIndex ()); style.setborderleft (cellstyle.border_thin); style.setleftbordercolor (indexedcolors.grey_50_percent.getIndex ()); style.setbordertop (cellstyle.border_thin); style.settopbordercolor (indexedColors.grey_50_percent.getIndex ()); style.setborderbottom (cellstyle.border_thin); style.setbottomborderColor (indexedColors.grey_50_percent.getIndex ()); Font DataFont = wb.createFont (); datafont.setfontname ( "arial"); datafont.setfontheightinpoints ((짧은) 10); style.setfont (datafont); Styles.put ( "데이터", 스타일); 스타일 = wb.createcellstyle (); style.clonestylefrom (styles.get ( "data")); style.setalignment (cellstyle.align_left); Styles.put ( "data1", Style); 스타일 = wb.createcellstyle (); style.clonestylefrom (styles.get ( "data")); style.setalignment (cellstyle.align_center); Styles.put ( "data2", Style); 스타일 = wb.createcellstyle (); style.clonestylefrom (styles.get ( "data")); style.setalignment (cellstyle.align_right); Styles.put ( "data3", Style); 스타일 = wb.createcellstyle (); style.clonestylefrom (styles.get ( "data")); // style.setwraptext (true); style.setalignment (cellstyle.align_center); style.setfillforegroundColor (indexedColors.grey_50_percent.getIndex ()); style.setfillpattern (cellstyle.solid_foreground); Font HeaderFont = wb.createFont (); HeaderFont.SetFontName ( "Arial"); headerfont.setfontheightinpoints ((짧은) 10); HeaderFont.SetBoldweight (font.boldweight_bold); HeaderFont.setColor (IndexEdColors.white.getIndex ()); style.setfont (HeaderFont); Styles.put ( "헤더", 스타일); 리턴 스타일; } / ** * * * @return 行对象 * / public row addrow () {return sheet.createrow (rownum ++); } / ** * * * @param row 添加的行 * @param column 添加列号 * @param val 添加值 * @return 单元格对象 * / public cell addcell (행, int 열, 객체 val) {return this.addcell (행, 열, val, 0, class.class); } / ** * * * @param row 添加的行 * @param column 添加列号 * @param val 添加值 * @param align 对齐方式 对齐方式 对齐方式 对齐方式 对齐方式 对齐方式 对齐方式 ■ : 靠左; 2 : 居中; 3 : 靠右 3 : @return 单元格对象 * / public cell addcell (행 칼럼, 객체 val, int align, class <?> fieldtype) {cell Cell = Row.cratecell (column); CellStyle Style = Styles.get ( "data"+(align> = 1 && align <= 3? Align : ""); try {if (val == null) {cell.setCellValue ( ""); } else if (val instanceof String) {cell.setCellValue ((String) val); } else if (val instanceof insteger) {cell.setCellValue ((Integer) val); } else if (val instanceof long) {cell.setCellValue ((long) val); } else if (val instanceof double) {cell.setCellValue (new DecimalFormat ( ". ######"). 형식 (val)); } else if (val instanceof float) {cell.setCellValue ((float) val); } else if (val instanceof date) {dataformat format = wb.createdataformat (); style.setDataFormat (format.getFormat ( "yyyy-mm-dd")); cell.setCellValue (dateUtils.formatdateTime ((날짜) val)); } else {if (fieldType! = class.class) {cell.setCellValue ((String) fieldType.getMethod ( "setValue", object.class) .invoke (null, val)); } else {cell.setCellValue ((string) class.forname (this.getClass (). getName (). replaceall (this.getClass (). getSimplename (), "fieldType."+val.getClass (). getSimplename ()+"type"). }}} catch (Exception Ex) {log.info ( "set cell value [" "+row.getRownum ()+", "+column+"] 오류 : "+ex.toString ()); cell.setCellValue (val.toString ()); } cell.setCellStyle (스타일); 리턴 셀; } / ** * * 添加数据 (通过 anotation.exportfield 添加数据) * @return list 数据列表 * / public <e> Exportexcel setDatalist (list <e> list) {for (e e : list) {int colunm = 0; 행 = this.addrow (); StringBuilder sb = new StringBuilder (); if (e instanceof map) {@suppresswarnings ( "선택 취소")지도 <string, object> map = (map <string, object>) e; for (문자열 키 : fieldmap.keyset ()) {object value = map.get (키); 문자열 columndicttype = dicttypes.get (colunm+""); if (stringUtils.isnotBlank (columnDictType)) {value = dictutils.getDictLabel (value == null? "": value.toString (), columnDictType, ""); } this.addcell (행, colunm ++, value == null? "": value.toString (), 0, String.class); sb.append (value + ","); }} else {for (object [] os : annotationList) {edcfelfield ef = (xcelfield) os [0]; 객체 val = null; // 엔티티 값을 얻습니다. {if (stringUtils.isnotBlank (ef.value ())) {val = reclections.invokeGetter (e, ef.value ()); } else {if (os [1] instanceof field) {val = reclections.invokegetter (e, (필드) OS [1]). getName ()); } else if (os [1] instanceof method) {val = reclections.invokemethod (e, (method) os [1]). getName (), new class [] {}, 새 개체 [] {}); }} // DICT 인 경우 DICT LABEL (stringUtils.isnotBlank (ef.dicttype ()) {val = dictutils.getDictLabel (val == null? "": val.toString (), ef.dicttype (), "; }} catch (Exception Ex) {// log.info를 무시하지 않는 실패 (ex.toString ()); val = ""; } this.addcell (행, colunm ++, val, ef.align (), ef.fieldtype ()); sb.append (val + ","); } log.debug ( "쓰기 성공 : ["+row.getRownum ()+"]"+sb.toString ()); }} 님이 reture; } / ** * * * @param os 输出数据流 * / public exportexcel write (outputstream os)는 ioexception {wb.write (os); 이것을 반환하십시오; } / ** * * * @param filename 输出文件名 * / public exportexcel write (httpservletResponse 응답, 문자열 filename)는 ioexception {response.reset (); response.setContentType ( "Application/Octet-stream; charset = utf-8"); response.setHeader ( "내용화", "첨부 파일; filename ="+encodes.urlencode (filename)); write (response.getOutputStream ()); 이것을 반환하십시오; } / ** * * * @param filename 输出文件名 * / public exportexcel writefile (String name)은 filenotfoundException, ioException {fileoutputStream os = new FileOutputStream (name); this.write (OS); 이것을 반환하십시오; } / ** * * * / public exportexcel dispose () {wb.dispose (); 이것을 반환하십시오; }}导出测试
public static void main (string [] args) 던지기 가능 {list <string> headerlist = lists.newarraylist (); for (int i = 1; i <= 10; i ++) {headerlist.add ( "表头"+i); } list <string> datarowlist = lists.newarrayList (); for (int i = 1; i <= headerlist.size (); i ++) {datarowlist.add ( "数据"+i); } list <list <string >> datalist = lists.newarrayList (); for (int i = 1; i <= 10000000; i ++) {datalist.add (datarowlist); } ExportExcel ee = 새로운 ExportExcel ( "表格标题", headerlist); for (int i = 0; i <datalist.size (); i ++) {row row = ee.addrow (); for (int j = 0; j <datalist.get (i) .size (); j ++) {ee.addcell (row, j, datalist.get (i) .get (j)); }} ee.writefile ( "대상/Export.xlsx"); ee.dispose (); log.debug ( "수출 성공"); }importexcel.java
/*** Copyright © 2012-2014 <a href = "https://github.com/thinkgem/jeesite"> jeesite </a> 모든 권리 보유. */package com.thinkgem.jeesite.common.utils.excel; import java.io.file; import java.io.fileinputstream; import java.io.ioexception; import java.io.inputstream; import java.lang.reflect.field; import java.lang.reflect.method; import java.util.collections; import java.util.com.com.comport; java.util.date; java.util.list; import org.apache.commons.lang3.stringutils; import org.apache.poi.hssf.usermodel.hssfworkbook; import org.apache.poi.openxml4j.exceptions.invalidformatexception; import org.apache.poi.ss.sermodel.cell; import; org.apache.poi.ss.usermodel.dateutil; import org.apache.poi.ss.usermodel.row; import org.apache.poi.ss.usermodel.sheet; import org.apache.poi.ss.usermodel.workbook; import org.apache.poi.xsssf.usermodel org.slf4j.logger; import org.slf4j.loggerfactory; import org.springframework.web.multipart.multipartfile; import com.google.common.collect.lists; import com.thinkgem.jeesite.common.utils.reflession; import com.thinkgem.jeesite.common.utils.excel.annotation.excelfield; import com.thinkgem.jeesite.modules.sys.utils.utils.dictutils; /** * 导入 Excel 文件 (支持 支持“XLS”和“XLSX”格式 格式} * @Author ThinkGem * @version 2013-03-10 */public class importExcel {private static logger log = loggerfactory.getLogger (importexcel.class); / ** * 工作薄对象 */ 개인 통합 문서 WB; / ** * 工作表对象 */ 개인 시트 시트; / ** * 标题行号 */ 개인 int Headernum; / ** * 构造函数 * @param path 导入文件 导入文件 导入文件, 读取第一个工作表 * @param headernum 标题行号 标题行号, 数据行号 = 标题行号 +1 * @throws invalidformatexception * @throws ioexception */ public importexcel (String filename, int headernum)은 InvalidformateXception, ioexception {this (filename), Headernum); } / ** * * * @param path 导入文件对象 导入文件对象 导入文件对象 导入文件对象 * @param headernum 标题行号, 数据行号 = 标题行号 +1 * @throws invalidformatexception * @throws ioexception * / public importexcel (파일 파일, int Headernum)은 InvalidFormateXception, ioException, IoException (this (파일, 헤드베르, 0); } / ** * * * @param path 导入文件 * @param headernum 标题行号 标题行号, 数据行号 = 标题行号 +1 * @param sheetindex 工作表编号 * @throws invalidformatexception * @throws ioexception * / public importexcel (문자열 filename, int headernum, int sheetindex) trows invalidformatexception, ioexception, ioexception, ioexception, ioexception, ioexception, ioexection sheetindex); } / ** * * * * @param path 导入文件对象 * @param headernum 标题行号 标题行号, 数据行号 = 标题行号 +1 * @param sheetindex 工作表编号 * @throws invalidformatexception * @throws ioexception * / public importexcel (파일 파일, int headernum, int sheetexception), ioexception, ioxception (파일) FileInputStream (파일), 헤드러늄, SheetIndex); } / ** * * * @param 파일 导入文件对象 * @param headernum 标题行号 标题行号, 数据行号 = 标题行号 +1 * @param sheetindex 工作表编号 * @throws invalidformatexception * @throws ioexception * / public importexcel (multipartfile multipartfile, int headernum, int sheeteDex) vallidformatex, ioexmention, ioexmention { this (multipartfile.getoriginalfilename (), multipartfile.getInputStream (), Headernum, SheetIndex); } / ** * * * @param path 导入文件对象 * @param headernum 标题行号 标题行号, 数据行号 = 标题行号 +1 * @param sheetindex 工作表编号 * @throws invalidformatexception * @throws ioexception * / public importexcel (문자열 filename, int headernum, int sheetindex) invalidcomeatex, io excement, if ioexemention {io excement ^ (StringUtils.isblank (filename)) {Throw New Runtimeexception ( "导入文档为空!"); } else if (filename.tolowercase (). endswith ( "xls")) {this.wb = new hssfworkbook (is); } else if (filename.tolowercase (). endswith ( "xlsx")) {this.wb = new xssfworkbook (is); } else {throw new runtimeexception ( "文档格式不正确!"); } if (this.wb.getNumberOfSheets () <sheetIndex) {throw new runtimeexception ( "文档中没有工作表!"); } this.sheet = this.wb.getsheetat (sheetIndex); this.headernum = headernum; log.debug ( "성공 초기화"); } / ** * * * @param rownum * @return * / public row getrow (int rownum) {return this.sheet.getrow (rownum); } / ** * * * @return * / public int getDatarownum () {return headernum+1; } / ** * * * @return * / public int getLastDatarOwnum () {return this.sheet.getLastrownum ()+헤드 ernum; } / ** * * * @return * / public int getLastCellNum () {return this.GetRow (헤드 더럼) .getLastCellNum (); } / ** * * * @param row 获取的行 * @param column 获取单元格列号 * @return 单元格值 * / public object getCellValue (행, int 열) {object val = ""; try {cell cell = row.getCell (열); if (cell! = null) {if (cell.getCellType () == cell.cell_type_numeric) {val = cell.getNumericCellValue (); } else if (cell.getCellType () == cell.cell_type_string) {val = cell.getStringCellValue (); } else if (cell.getCellType () == cell.cell_type_formula) {val = cell.getCellFormula (); } else if (cell.getCellType () == cell.cell_type_boolean) {val = cell.getBooleanCellValue (); } else if (cell.getCellType () == cell.cell_type_error) {val = cell.geterRorcellValue (); }}} catch (예외 e) {return val; } return val; } / ** * * * @param cls 导入对象类型 * @param groups 导入分组 * / public <e> list <e> getDatalist (class <e> cls, int ... groups)는 인스턴스티션 exception, 불법적 인 {object []> annotationList = lists.newarraylist (); // 주석 필드 필드를 가져옵니다 [] fs = cls.getDeclaredFields (); for (field f : fs) {excelfield ef = f.getAnnotation (xcelfield.class); if (ef! = null && (ef.type () == 0 || ef.type () == 2)) {if (groups! = null && groups.length> 0) {boolean ingroup = false; for (int g : groups) {if (ingroup) {break; } for (int efg : ef.groups ()) {if (g == efg) {ingroup = true; AnnotationList.add (new Object [] {ef, f}); 부서지다; }}}} else {AnnotationList.add (new Object [] {ef, f}); }}} // get get annotation method method [] ms = cls.getDeclaredMethods (); for (method m : ms) {excelfield ef = m.getAntotation (xcelfield.class); if (ef! = null && (ef.type () == 0 || ef.type () == 2)) {if (groups! = null && groups.length> 0) {boolean ingroup = false; for (int g : groups) {if (ingroup) {break; } for (int efg : ef.groups ()) {if (g == efg) {ingroup = true; AnnotationList.add (new Object [] {ef, m}); 부서지다; }}}} else {AnnotationList.add (new Object [] {ef, m}); }}} // Field Sorting Collections.SORT (AnnotationList, New Comparator <Object []> () {public int compart (object [] o1, object [] o2) {return new Integer (((excelfield) O1 [0]). Sort ()) //log.debug("Import 열 수 : "+AnnotationList.size ()); // Excel 데이터 목록 가져 오기 <e> datalist = lists.newarraylist (); for (int i = this.getDatarownum (); i <this.getlastDatarownum (); i ++) {e e = (e) cls.newinstance (); int 열 = 0; 행 = this.getrow (i); StringBuilder sb = new StringBuilder (); for (object [] os : annotationList) {Object val = this.getCellValue (행, 열 ++); if (val! = null) {edcfelfield ef = (accelfield) os [0]; // DICT 유형 인 경우 (stringUtils.isnotBlank (ef.dicttype ()) {val = dictutils.getDictValue (val.tostring (), ef.dicttype (), ") if if if if if if if if if if if if if if if를받습니다. //log.debug("Dictionary 유형 값 : [ "+i+", "+colunm+"] "+val); } // 매개 변수 유형 및 유형 캐스트 클래스를 얻습니다 <?> valtype = class.class; if (os [1] instanceof field) {valtype = ((필드) OS [1]). getType (); } else if (os [1] instanceof method) {메소드 메소드 = (메소드) OS [1]); if ( "get".equals (method.getName (). substring (0, 3))) {valtype = method.getReturnType (); } else if ( "set".equals (method.getName (). substring (0, 3))) {valtype = ((method) os [1]). getParameterTypes () [0]; }} //log.debug("Import 값 유형 : [ "+i+", "+column+"] "+valtype); try {if (valtype == string.class) {string s = string.valueof (val.toString ()); if (stringUtils.endswith (s, ".0")) {val = stringUtils.substringbefore (s, ".0"); } else {val = string.valueof (val.toString ()); }} else if (valtype == integer.class) {val = double.valueof (val.toString ()). intValue (); } else if (valtype == long.class) {val = double.valueof (val.toString ()). longValue (); } else if (valtype == double.class) {val = double.valueof (val.toString ()); } else if (valtype == float.class) {val = float.valueof (val.toString ()); } else if (valtype == date.class) {val = dateUtil.getJavadate ((double) val); } else {if (ef.fieldType ()! = class.class) {val = ef.fieldType (). getMethod ( "getValue", String.class) .invoke (null, val.toString ()); } else {val = class.forname (this.getClass (). getName (). replaceall (this.getClass (). "fieldType."+valtype.getSimplename ()+"type"). getMethod ( "getValue", String.class). }}} catch (예외) {log.info ( "셀 값 ["+i+","+column+"] 오류 :"+ex.toString ()); val = null; } // (os [1] instanceof field) {reflections.invokesetter (e, ((필드) OS [1]). getName (), val); } else if (os [1] instanceof method) {문자열 mthodname = ((method) os [1]). getName (); if ( "get".equals (mthodname.substring (0, 3))) {mthodname = "set"+stringUtils.substringAfter (mthodname, "get"); } reflections.invokemethod (e, mthodname, new class [] {valtype}, new Object [] {val}); }} sb.append (val+","); } datalist.add (e); log.debug ( "성공 읽기 : ["+i+"]"+sb.tostring ()); } return datalist; }}导入测试
public static void main (string [] args) 던지기 가능 {importexcel ei = new importexcel ( "target/export.xlsx", 1); for (int i = ei.getDatarownum (); i <ei.getlastDatarownum (); i ++) {row row = ei.getrow (i); for (int j = 0; System.out.print (val+","); } system.out.print ( "/n"); }}