1

I made a randomly generated list of people with names, ages, weight, height, etc. in Excel. I would like to know how I can use the information in Excel to create a "Person" in Java so that each file would contain the information of each person created in Excel. There are about 200,000 "People". For example a Java template: "name = [INSERT FROM EXCEL CELL A1]" then goes to "age = [INSERT FROM EXCEL CELL A2]" and it does this for the first row then saves the file and uses the empty variable template again and does this for the 200,000 individuals. Is this possible or will I have to do this by hand? Can this be automated?

4

3 回答 3

2

以CSV 格式保存 excel 文件。CSV 相对容易读写,是行业认可的格式。

于 2013-08-15T20:54:48.893 回答
1

将您的 excel 文件另存为 .xml,然后在 java 中解析该数据。正如其他人所说,您还可以将其保存为 .csv 文件,您也可以在 java 中解析该文件。

于 2013-08-15T20:59:23.473 回答
0

您可以使用opencsv将每一行转换为 bean。您需要将您的 excel 保存为csv文件。

CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));

ColumnPositionMappingStrategy strat = new ColumnPositionMappingStrategy();
strat.setType(Person.class);

// the fields to bind do in your JavaBean
String[] columns = new String[] {"name", "age"}; 
strat.setColumnMapping(columns);

CsvToBean csv = new CsvToBean();
List list = csv.parse(strat, reader); // the people
于 2013-08-15T21:03:14.430 回答