Name |
Age |
Subjects |
Scores |
Name of teacher |
Teacher Sex |
Bachelor |
12 |
Chinese |
80 |
Zhang Sanfeng |
Man |
We require that the import data contain no accounts and fractions.
Import Demo Testexcelindex class
package example;
Import Java.io.File;
Import Java.io.FileInputStream;
Import java.util.List;
Import Java.util.Map;
Import model. Student;
Import Test. Abstractexceltest;
Import com.easyReport.read.temp.PropertyTemp;
Import com.easyReport.read.temp.ReadTemp;
Import Formater. Sexformater;
public class Testexcelindex extends Abstractexceltest<student> {
@Override
public void Test () {
FileInputStream FileInputStream;
try {
FileInputStream = new FileInputStream (New File ("Testfile/test4.xls"));
Testreadbean (FileInputStream);
Testreadmap (FileInputStream);
Fileinputstream.close ();
} catch (Exception e) {
E.printstacktrace ();
}
}
@Override
Protected Readtemp bulidreadtemp () {
Readtemp readtemp = new Readtemp (1);
Readtemp.addpropertytemp (New Propertytemp ("name", "name"));
Readtemp.addpropertytemp (New Propertytemp ("Age", "ages");
Readtemp.addpropertytemp (New Propertytemp ("Teacher name", "Teachers.name", 4));
Readtemp.addpropertytemp (New Propertytemp ("Teacher Gender", "Teachers.sex", New Sexformater ()));
return readtemp;
}
@Override
protected void Writebeanlist (list<student> modellists) {
System.out.println ("--------------bean---------------");
for (Student s:modellists) {
System.out.println (S.getname () + "|"
+ s.getage () + "|" +s.getteachers (). Get (0));
}
}
@Override
protected void Writemaplist (list<map<string, object>> maplists) {
SYSTEM.OUT.PRINTLN ("--------------map---------------");
For (map<string, object> m:maplists) {
System.out.println (M.get ("name") + "|" + m.get ("age") +
"|" +m.get ("teachers.name") + "|" +m.get ("Teachers.sex"));
}
}
}
Operation Result:
--------------Bean---------------
Bachelor |12| Zhang Sanfeng | M
Readtemp.addpropertytemp (New Propertytemp ("Teacher name", "Teachers.name", 4));
Propertytemp construct method to specify cell index, default is 0
Public Propertytemp (string title, String propertyname, Integer cellindex) {
Super ();
This.title = title;
This.propertyname = PropertyName;
This.cellindex = CellIndex;
}
Readtemp.addpropertytemp (propertytemp);
For each property template added, if no index value is specified, the cell index value is automatically added, and if the specified index value is less than or equal to the previous cell index, it will automatically add 1.
Readtemp readtemp = new Readtemp (1);
Specifies that the read row index is 1, which reads the data from line 2nd and does not specify a default of 0.
This article is from "Rookie Bobo" blog, please be sure to keep this source http://zhangxiao2.blog.51cto.com/6342789/1586568
Java easyreport Import Excel, txt data row and column index (iv)