文件导入导出必须代码
Exportexcel.java
/*** Copyright © 2012-2014 <a href = "https://github.com/thinkgem/jeesite"> Jeesit </a> Alle Rechte vorbehalten. */paket com.thinkgem.jeeesit.common.utils.excel; importieren java.io.filenotfoundException; import Java.io.FileOutputStream; Import java.io.ioxception; import Java.io.outputStream; Import Java.Lang.reflect.field; java.util.comPparator; import Java.util.date; import Java.util.hashMap; Import Java.util.linkedHasMap; Import Java.util.List; Import Java.util.map; importieren javax.servlet.http.httpServletResponse; import org.apache.commons.lang3.stringutils; import org.apache.poi.s.usermodel.cell; import org.apache.poi.s.usmodel.cellstyle; org.apache.poi.ss.usmodel.font; import org.apache.poi.s.usmodel.indexedcolors; import org.apache.poi.s.usmodel.row; org.apache.poi.s.util.cellrangeadress; import org.apache.poi.xssf.streaming.sxssfworkbook; import org.apache.poi.xssf.usmodel.xssfclientanchor; org.slf4j.logger; import org.slf4j.loggerfactory; import com.google.common.collect.lists; import com.thinkgem.jeesit.common com.thinkgem.jeeesit.common.utils.excel.annotation.excelfield; import com.thinkgem.jeesit.modules.sys.utils.dictutils; /** * 导出 excel 文件(导出 "xlsx" 格式 , 支持大数据量导出 @see org.apache.poi.sss.spreadsheetversion) * @author Thinkgem * @version 2013-04-21 */public class exportexcel {private statische Logger-Logger-Loggerfaktor. / ** * 工作薄对象 */ privat sxssfWorkbook WB; / ** * 工作表对象 */ privates Blatt; / ** * 样式列表 */ private map <String, CellStyle> Stile; / ** * 当前行号 */ private int rownum; /** * 注解列表( Object [] {Excelfield, Feld/Methode}) */list <Object []> AnnotationList = lists.newarrayList (); / ** * 字段 map */ linkedHashMap <String, String> FieldMap; HashMap <String, String> dikttypes; / ** * 构造函数 * @param title 表格标题 , 传 传 空值 空值 , 表示无标题 * @param cls 实体对象 , 通过 Annotation. } / ** * 构造函数 * @param title 表格标题 , 传 传 空值 空值 , 表示无标题 * @param fieldMap , 获取要导出的字段和字段标题 * / public exportexcel (String -Titel, linkedHashMap <String, String> FieldMap) {this.fieldMap = fieldMap; dikttypes = new HashMap <String, String> (); // initialisieren int colunm = 0; List <String> HeaderList = lists.NewarrayList (); für (String -Schlüssel: fieldMap.keyset ()) {String t = fieldMap.get (Schlüssel); HashMap <String, String> map = com.tinkgem.jeeSite.common.utils.stringutils.tomap (t, ";", "=", false); if (map.get ("name")! = null) {t = map.get ("name"); } if (map.get ("dikttype")! } colunm ++; HeaderList.Add (t); } initialize (Titel, HeaderList); } /** * 构造函数 * @param title 表格标题,传“空值”,表示无标题 * @param cls 实体对象,通过annotation.ExportField获取标题 * @param type 导出类型(1:导出数据;2:导出模板) * @param groups 导入分组 */ public ExportExcel(String title, Class<?> cls, int type, int... groups){ // Get annotation field Field[] fs = cls.getDeclaredfields (); für (Feld f: fs) {excelfield ef = f.getannotation (excelfield.class); if (ef! für (int g: gruppen) {if (ingroup) {break; } für (int efg: ef.groups ()) {if (g == efg) {ingroup = true; AnnotationList.add (neues Objekt [] {ef, f}); brechen; }}}} else {AnnotationList.add (neues Objekt [] {ef, f}); }}} // Annotationsmethode erhalten [] ms = cls.getDeclaredMethods (); für (Methode m: ms) {excelfield ef = M.Getannotation (excelfield.class); if (ef! für (int g: gruppen) {if (ingroup) {break; } für (int efg: ef.groups ()) {if (g == efg) {ingroup = true; AnnotationList.add (neues Objekt [] {ef, m}); brechen; }}}} else {AnnotationList.add (neues Objekt [] {ef, m}); }}} // Feldsortierkollektorens.sort (AnnotationList, neuer Vergleiche <FOLGING []> () {public int compare (Object [] O1, Objekt [] O2) {return New Integer (((excelfield) o1 [0]). Sort (). // list initialisieren <string> HeaderList = lists.newarrayList (); für (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); } initialize (Titel, HeaderList); } / ** * 构造函数 * @param title 表格标题 , 传 传 空值 空值 , 表示无标题 * @param header 表头数组 * / public exptexcel (String title, String [] Header) {initialize (title, lists.newarrayList (Header)); } / ** * 构造函数 * @param Titel 表格标题 , 传 传 空值 空值 , 表示无标题 * @param Headerlist 表头列表 * / public extexcel (String -Titel, Liste <string> Headerlist) {initialize (title, HeaderList); } / ** * 初始化函数 * @param title 表格标题 , 传 传 空值 空值 , 表示无标题 * @param Headerlist 表头列表 * / private void initialize (String -Titel, Liste <string> Headerlist) {this.wb = new SXSSFWORKBOOK (500); this.sheet = wb.createSheet ("Export"); this.styles = Createstiles (WB); // title if (stringutils.isnotblank (title)) {rowtlerow = Sheet.CreateRow (Rownum ++); titlerow.seteightheightinpoints (30); Cell titlecell = titlerow.createcell (0); titlecell.setcellstyle (styles.get ("title")); titlecell.setcellValue (Titel); Sheet.AddmergedRegion (New CellRangeaddress (Titlerow.getRownum (), Titlerow.getRownum (), Titlerow.getRownum (), Headerlist.size ()-1)); } // Header erstellen if (HeaderList == NULL) {Neue RunTimeException werfen ("HeaderList Not Null!"); } Row Headerrow = Sheet.CreateRow (Rownum ++); Kopftaures.SetheightHeightIntinpoints (16); für (int i = 0; i <HeaderList.size (); i ++) {cell Cell = headerrow.createcell (i); cell.setCellStyle (styles.get ("Header")); String [] ss = Stringutils.Split (HeaderList.get (i), "**", 2); if (ss.Length == 2) {cell.setCellValue (SS [0]); Kommentar Kommentar = this.sheet.createdrawingPatriarch (). CreateCellCompment (neuer XSSFClientanchor (0, 0, 0, 0, (kurz) 3, 3, (kurz) 5, 6)); comment.setString (neuer XSSFrichTextString (SS [1]); cell.setCellCompment (Kommentar); } else {cell.setCellValue (HeaderList.get (i)); } Sheet.AutoSizeColumn (i); } für (int i = 0; i <HeaderList.size (); i ++) {int colwidth = sheet.getColumnwidth (i)*2; Sheet.SetColumnwidth (i, colwidth <3000? 3000: colwidth); } log.debug ("Erfolg initialisieren"); } / ** * 创建表格样式 * @param wb 工作薄对象 * @return 样式列表 * / private map <string, cellstyle> createstiles (Arbeitsbuch WB) {map <string, cellstyle> styles = new HashMap <String, Cellstyle> (); CellStyle style = wb.CreateCellStyle (); style.setAnignment (CellStyle.Align_Center); style.setverticalInnment (CellStyle.vertical_Center); Font titleFont = wb.CreateInont (); titleFont.setFontName ("Arial"); titleFont.setFontHeightIntinpoints ((kurz) 16); titleFont.setBoldWeight (font.boldgewicht_bold); style.setFont (titleFont); styles.put ("title", style); style = wb.createcellstyle (); style.setverticalInnment (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.CreateInont (); DataFont.SetFontName ("Arial"); DataFont.SetFontHeightIntinPoints ((kurz) 10); style.setFont (DataFont); styles.put ("data", style); style = wb.createcellstyle (); style.clonestyleFrom (styles.get ("Daten")); style.setAnignment (CellStyle.Align_Left); styles.put ("data1", style); style = wb.createcellstyle (); style.clonestyleFrom (styles.get ("Daten")); style.setAnignment (CellStyle.Align_Center); styles.put ("data2", style); style = wb.createcellstyle (); style.clonestyleFrom (styles.get ("Daten")); style.setAnignment (CellStyle.Align_Right); styles.put ("data3", style); style = wb.createcellstyle (); style.clonestyleFrom (styles.get ("data")); // style.setWraptext (true); style.setAnignment (CellStyle.Align_Center); style.setFillforegroundColor (indexedColors.grey_50_percent.getIndex ()); style.setFillpattern (CellStyle.solid_foreground); Font Headerfont = wb.CreateIneT (); HeaderFont.SetFontName ("Arial"); Headerfont.SetFontHeightIntinPoints ((kurz) 10); Headerfont.SetBoldWeight (font.boldweight_bold); Headerfont.setColor (indexedColors.white.getIndex ()); style.setFont (Headerfont); styles.put ("Header", Stil); Rückkehrstile; } / ** * 添加一行 * @return 行对象 * / public row adDrow () {return Sheet.CreateRow (Rownum ++); } / ** * 添加一个单元格 * @param Zeile 添加的行 * @param Spalte 添加列号 * @param val 添加值 * @return 单元格对象 * / public Cell AddCell (Zeilenzeile, int Spalte, Objekt val) {return this.addcell (Zeile, Spalte, Val, 0, Klasse.Class); } / ** * 添加一个单元格 * @param Zeile 添加的行 * @param Spalte 添加列号 * @param val 添加值 * @param Align 对齐方式( 1 : 靠左; 2 : 居中; 3 : 靠右) * @return 单元格对象 * / public Cell addCell (Zeilenzeile, Int -Spalte, Objekt val, int Align, class <> fieldtype) {cell Cell = row.create CellStyle style = styles.get ("Daten"+(Align> = 1 && Align <= 3? Align: "")); try {if (val == null) {cell.setCellValue (""); } else if (val instanceof string) {cell.setCellValue ((String) val); } else if (val Instance von Integer) {cell.setCellValue ((Integer) Val); } else if (val instanceof long) {cell.setCellValue ((long) val); } else if (val instanceof double) {cell.setCellValue (neue DecimalFormat (". ##### ##"). Format (Val)); } else if (val instanceof float) {cell.setCellValue ((float) val); } else if (val InstanceOf Datum) {dataFormat format = wb.CreatedataFormat (); style.setDataFormat (format.getFormat ("yyyy-mm-dd")); cell.setCellValue (DATEUTILS.FormatDatetime ((Datum) Val)); } else {if (fieldType! } else {cell.setCellValue ((String) class.forname (this.getClass (). getName (). Ersatzung (this.getClass (). GetSimpename (), "fieldType."+val.getClass (). }}} catch (Exception ex) {log.info ("Zellwert setzen ["+row.getRownum ()+","+Spalte+"] Fehler:"+ex.toString ()); cell.setCellValue (Val.ToString ()); } cell.setCellStyle (Stil); Zelle zurück; } / ** * 添加数据(通过 Annotation.exportfield 添加数据) * @return list 数据列表 * / public <E> exportexcel setDatalist (Liste <e> liste) {for (e e: list) {int colunm = 0; Row row = this.addrow (); StringBuilder sb = new StringBuilder (); if (e instanceof map) {@suppresswarnings ("deaktiviert") map <String, Objekt> map = (map <String, Objekt>) e; für (String -Schlüssel: fieldMap.keyset ()) {Object value = map.get (Schlüssel); String columnDictType = dikttypes.get (colunm+""); if (stringutils.isnotblank (columnDictType)) {value = dictutils.getDictLabel (value == null? "": value.toString (), columnDictType, ""); } this.addcell (row, colunm ++, value == null? "": value.toString (), 0, String.class); sb.Append (Wert + ","); }} else {for (Object [] os: AnnotationList) {excelfield ef = (excelfield) os [0]; Objekt val = null; // Entitätswert try {if (stringutils.isnotblank (ef.value ())) {val = reflections.invoketter (e, ef.value ()); } else {if (os [1] Instanz des Feldes) {val = reflections.invoketter (e, (field) os [1]). getName ()); } else if (os [1] Instanzmethode) {val = reflections.invokemethod (e, (Methode) os [1]). getName (), neue Klasse [] {}, neues Objekt [] {}); }} // if dict, erhalten Sie dict label if (stringutils.isnotblank (ef.dictType ()) {val = dictutils.getDictLabel (val == null? " }} catch (Ausnahme ex) {// Versäumnis, log.info (ex.toString ()) zu ignorieren; val = ""; } this.addcell (row, colunm ++, val, ef.Anign (), ef.fieldType ()); Sb.Append (Val + ","); } log.debug ("Erfolg schreiben: ["+row.getRownum ()+"]"+sb.toString ()); }} zurückgeben; } / ** * 输出数据流 * @param os 输出数据流 * / public exportexcel write (outputStream os) löscht ioException {wb.write (os); gib dies zurück; } / ** * 输出到客户端 * @param Dateiname 输出文件名 * / public exportexcel write (httpServletResponse -Antwort, String -Dateiname) löscht IOException {response.reset () aus; Antwort.SetContentType ("Anwendung/Oktett-Stream; CharSet = UTF-8"); response.setheader ("Inhaltsdisposition", "Anhang; Dateiname ="+codes.urlencode (Dateiname)); write (response.getOutputStream ()); gib dies zurück; } / ** * 输出到文件 * @param Dateiname 输出文件名 * / public exportexcel writeFile (String -Name) löst FileNotFoundException, IOException {FileOutputStream OS = new FileOutputStream (Name) aus; this.write (os); gib dies zurück; } / ** * 清理临时文件 * / public exportexcel dispose () {wb.dispose (); gib dies zurück; }}导出测试
public static void main (String [] args) löst Throwable {list <string> headerlist = lists.newarrayList () aus; für (int i = 1; i <= 10; i ++) {HeaderList.add ("表头"+i); } List <string> datarowlist = lists.NewarrayList (); für (int i = 1; i <= HeaderList.size (); i ++) {datarowlist.add ("数据"+i); } List <list <string >> datalist = lists.NewarrayList (); für (int i = 1; i <= 1000000; i ++) {datalist.add (datarowlist); } Exportexcel ee = new Extexcel ("表格标题", HeaderList); für (int i = 0; i <datalist.size (); i ++) {row row = ee.addrow (); für (int j = 0; j <datalist.get (i) .Size (); j ++) {ee.addcell (row, j, datalist.get (i) .get (j)); }} ee.writeFile ("Ziel/export.xlsx"); ee.disponse (); log.debug ("Export -Erfolg"); }ImportExcel.java
/*** Copyright © 2012-2014 <a href = "https://github.com/thinkgem/jeesite"> Jeesit </a> Alle Rechte vorbehalten. */paket com.thinkgem.jeeesit.common.utils.excel; import Java.io.file; import Java.io.fileinputstream; Import Java.io.ioxception; Import Java.io.inputStream; Import Java.lang.reflect.field; importieren Sie Java.lang.Reflect.Method; Method; Import Java.util.Collections; Java.util.List; import org.apache.commons.lang3.stringutils; import org.apache.poi.hssf.usermodel.hssfworkbook; import org.apache.poi.openxml4j.exceptions.invalidformatexception; import.apache.poi.Usermodel.Usermodel.Usermodel.Usermodel.Usermodel.Usermodel.Usermodel.Usermodel.Usermodel.Usermodel.Usermodel.Usermodel.Usermodel.Usermodel. org.apache.poi.ss.usmodel.dateutil; import org.apache.poi.s.usmodel.row; import org.apache.poi.s.usmodel.sheet; org.slf4j.logger; import org.slf4j.loggerfactory; import org.springframework.web.multipart.multiPartFile; import com.google.common.collect.lists; import com.thinkgem.jeesit.common /** * 导入 excel 文件(支持 "xls" 和 "xlsx" 格式) * @author Thinkgem * @Version 2013-03-10 */public class Importexcel {private statische Logger log = loggerfactory.getLogger (ImportExcel.class); / ** * 工作薄对象 */ privates Arbeitsbuch WB; / ** * 工作表对象 */ privates Blatt; / ** * 标题行号 */ privat int headernum; / ** * 构造函数 * @param Pfad 导入文件 , 读取第一个工作表 * @param Headernum 标题行号 , 数据行号 = 标题行号 +1 * @Throws InvalyFormatexception * @Throws ioException */ public importexcel (String -Datei, int Headernum) wirft InvalyFormatexception, ioException {this New File (fileName), Headernum); } / ** * 构造函数 * @param Pfad 导入文件对象 , 读取第一个工作表 * @param Headernum 标题行号 , 数据行号 = 标题行号 +1 * @Throws InvalyFormatexception * @throws ioException * / public importexcel (Dateidatei, int Headernum) wirft InvalyFormatexception, iOException {this (Datei, Headernum, 0) aus; } /** * 构造函数 * @param path 导入文件 * @param headerNum 标题行号,数据行号=标题行号+1 * @param sheetIndex 工作表编号 * @throws InvalidFormatException * @throws IOException */ public ImportExcel(String fileName, int headerNum, int sheetIndex) throws InvalidFormatException, IOException { this(new File(fileName), headerNum, sheetIndex); } / ** * 构造函数 * @param Pfad 导入文件对象 * @param headernum 标题行号 , 数据行号 = 标题行号 +1 * @param SheetIndex 工作表编号 * @throws InvalyFortexception * @throws ioException * / public importexcel (Dateidatei, Int Headernum, IntheTintEx) löscht InvalyFormTexceNputle, ioExcel {thate. BlattIndex); } / ** * 构造函数 * @param Datei 导入文件对象 * @param Headernum 标题行号 , 数据行号 = 标题行号 +1 * @param SheetIndex 工作表编号 * @Throws InvalyFormatexception * @Throws ioException * / public importExcel (MultiPartFile MultiPartFile, Int Headernum, Int.Sportex. this (multipartFile.getOriginalFileName (), MultiPartFile.getInputStream (), Headernum, SheetIndex); } / ** * 构造函数 * @param Pfad 导入文件对象 * @param Headernum 标题行号 , 数据行号 = 标题行号 +1 * @param Sheetindex 工作表编号 * @throws InvalyFortexception * @throws ioException * / public importexcel (String Filename, InputStream IS, Int.InNex). neue runimeexception werfen ("导入文档为空!"); } else if (Dateiname.tolowerCase (). EndsWith ("xls")) {this.wb = new HSSFWorkbook (IS); } else if (fileName.tolowerCase (). EndsWith ("xlsx")) {this.wb = new XSSFWorkbook (IS); } else {werfen Sie eine neue RunTimeException ("文档格式不正确!"); } if (this.wb.getNumberofSheets () <SheetIndex) {neue runTimeexception ("文档中没有工作表!"); } this.sheet = this.wb.getsheetat (SheetIndex); this.HeaDernum = Headernum; log.debug ("Erfolg initialisieren"); } / ** * 获取行对象 * @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 ()+Headernum; } / ** * 获取最后一个列号 * @return * / public int getLastcellnum () {return this.getRow (Kopfstärke) .GetLastcellnum (); } / ** * 获取单元格值 * @param row 获取的行 * @param Spalte 获取单元格列号 * @return 单元格值 * / public Object getCellValue (Zeilenzeile, int Spalte) {Object val = ""; try {cell cell = row.getCell (Spalte); if (cell! } 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 (Ausnahme e) {return val; } return val; } / ** * 获取导入数据列表 * @param cls 导入对象类型 * @param gruppen 导入分组 * / public <e> list <e> getDatalist (class <e> cls, int ... gruppen) löst die InstanziationException aus, illegalAccessException {list <eljekts <]> AnnotationList = Lists.NewarrayList (); // Annotationsfeld erhalten [] fs = cls.getDeclaredfields (); für (Feld f: fs) {excelfield ef = f.getannotation (excelfield.class); if (ef! = null && (ef.type () == 0 || ef.type () == 2)) {if (gruppen! für (int g: gruppen) {if (ingroup) {break; } für (int efg: ef.groups ()) {if (g == efg) {ingroup = true; AnnotationList.add (neues Objekt [] {ef, f}); brechen; }}}} else {AnnotationList.add (neues Objekt [] {ef, f}); }}} // Annotationsmethode erhalten [] ms = cls.getDeclaredMethods (); für (Methode m: ms) {excelfield ef = M.Getannotation (excelfield.class); if (ef! = null && (ef.type () == 0 || ef.type () == 2)) {if (gruppen! für (int g: gruppen) {if (ingroup) {break; } für (int efg: ef.groups ()) {if (g == efg) {ingroup = true; AnnotationList.add (neues Objekt [] {ef, m}); brechen; }}}} else {AnnotationList.add (neues Objekt [] {ef, m}); }}} // Feldsortierkollektorens.sort (AnnotationList, neuer Vergleiche <FOLGING []> () {public int compare (Object [] O1, Objekt [] O2) {return New Integer (((excelfield) o1 [0]). Sort (). //log.debug("import Spalte Anzahl: "+AnnotationList.size ()); // Excel Data List <E> datalist = lists.NewarrayList () abrufen; für (int i = this.getDatarownum (); i <this.getLastDatarownum (); i ++) {e e = (e) cls.newinstance (); int column = 0; Row row = this.getRow (i); StringBuilder sb = new StringBuilder (); für (Object [] os: AnnotationList) {Object val = this.getCellValue (Zeile, Spalte ++); if (val! = null) {excelfield ef = (excelfield) os [0]; // if dict type, dict value if (stringutils.isnotblank (ef.dictType ()) {val = dictutils.getDictValue (val.toString (), ef.DictTyPe (), ""); //log.debug("Dictionary -Typ Wert: ["+i+", "+colunm+"] "+val); } // Paramtyp und Typ Cast Class <?> Valtype = class.class; if (os [1] Instanz des Feldes) {valType = ((field) os [1]). gettType (); } else if (os [1] Instanzmethode) {Methode Methode = ((Methode) OS [1]); if ("get" .equals (methode.getName (). substring (0, 3)) {valtype = methode.getReturnType (); } else if ("set" .equals (methode.getName (). substring (0, 3)) {valType = ((Methode) os [1]). getParameterTypes () [0]; }} //log.debug("import Value Typ: ["+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 ((doppelt) val); } else {if (ef.fieldType ()! = class.class) {val = ef.fieldType (). } else {val = class.forname (this.getClass (). getName (). ersetzen (this.getClass (). GetImplename (), "FieldType."+valtype.getSimPename ()+"Typ"). }}} catch (Exception ex) {log.info ("cell value ["+i+","+column+"] Fehler:"+ex.toString ()); val = null; } // Entitätswert festlegen if (os [1] Instanz des Feldes) {Reflections.invokesetter (e, ((Feld) os [1]). getName (), val); } else if (os [1] Instanzmethode) {String mThodname = ((Methode) OS [1]). getName (); if ("get" .equals (mthodname.substring (0, 3)) {mthodname = "set"+stringutils.substringAfter (MTHODNAME, "GET"); } Reflectionss.invokemethod (e, mthodname, new class [] {valType}, neues Objekt [] {val}); }} SB.Append (Val+","); } datalist.add (e); log.debug ("Erfolg lesen: ["+i+"]"+sb.toString ()); } return Datalist; }}导入测试
public static void main (String [] args) löst Throwable {Importexcel EI = new ImportExcel ("Ziel/export.xlsx", 1) aus; für (int i = ei.getDatarownum (); i <ei.getLastDatarownum (); i ++) {row row = ei.getRow (i); für (int j = 0; j <ei.getLastcellnum (); j ++) {Object val = ei.getCellValue (row, j); System.out.print (Val+","); } System.out.print ("/n"); }}