Java easyreport Import Excel, txt data row and column index (iv)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.