写入数据到excel中
@Test
public void test19() throws Exception{
List<List<String>> contentList = new ArrayList<>();
register("15755789966");
for (String str : BaseConst.SUBJECT_ARR) {
String s = “[{"Key":1,"Value":"选择题"},{"Key":3,"Value":"多选题"}]”
cn.hutool.json.JSONArray objects = new cn.hutool.json.JSONArray();
objects = JSONUtil.parseArray(s);
for (Object obj1 : objects) {
List<String> content = new ArrayList<>();
String jsonString = JSON.toJSONString(obj1);
Map maps2 = (Map) JSON.parse(jsonString);
String listJson = maps2.get("Value").toString();
String Key = maps2.get("Key").toString();
content.add(str);
content.add(Key);
content.add(listJson);
contentList.add(content);
}
}
ImportForm(contentList);
}
public void ImportForm(List<List<String>> contentList){
List<String> headList = new ArrayList<>();
headList.add("name");
headList.add("edition_id");
headList.add("edition_name");
List<List<List<String>>> lists = StringUtil.averageAssign(contentList, 1);
System.out.println();
for (int i = 0; i < lists.size(); i++) {
WriteToExcel.setSheet("WorkSheet"); //创建sheet页
WriteToExcel.createHead(headList); //设置表头
WriteToExcel.createContent(lists.get(i)); //设置内容
WriteToExcel.writeToFile("C://Users//Administrator//Desktop//教材111//教材"+"---ml.xlsx"); //写入文件
}
}
就是这样