我有这样的数据(来自解析JSON文件)。我想使用Apache POI或任何其他jar将其转换为excel表。 数据是:
heading1 ---> 2014-01-15 00:00:00.0
heading2 ---> A5CD51
heading3
heading4
sub-head41---> 1235148727
sub-head42---> 8015
sub-head43---> 9999-12-31
sub-head44---> 1962-07-09
heading5
sub-head51---> 2014-01-15
sub-head52---> 0
sub-head53---> 175_INFA-BATCH
heading6---> 994127F
heading1---> 2014-11-24 00:00:00.0
heading2---> 28F313
heading3
heading4
sub-head41 ---> 1235148727
sub-head42 ---> 8015
sub-head43 ---> 9999-12-31
sub-head44 ---> 1962-07-09
heading5
heading51---> 2014-11-24
heading52---> 1
heading53---> 343_INFA-BATCH
heading6---> 324343
这应该转换为excel,如下所示:
我从中获取数据的示例JSON是
"heading1 ":"994127F79137C42A38823F498F1496C2",
"heading3"{ },
"heading2 ":"A5CD51AC07214EF3FEB6563E4B1CEE38",
"heading3":"2014-01-15 00:00:00.0",
"heading4":{
"sub-head41":"2F94846E636273BD837BA47732D66613",
"sub-head42":"178",
"sub-head43":"1962-07-09"
},
我用来解析JSON并获取数据的示例代码:
String innerObjKey = (String) segmentSetitr.next();
if(innerObj.get(innerObjKey)instanceof JSONObject)
{
JSONObject innerEle = (JSONObject) innerObj.get(innerObjKey);
System.out.println(innerObjKey);
Set<String> innerObjSet = innerObj.keySet();
Iterator innerObjSetitr = innerObjSet.iterator();
while (innerObjSetitr.hasNext()) {
String key = (String) innerObjSetitr.next();
System.out.println("\t " + key + " ---> " + innerObj.get(key));
}else
{
System.out.println(innerObjKey + " ---> " + innerObj.get(innerObjKey));
cell.setCellValue((String) innerObjKey);
}
在这一切中,所有领域都是动态的。标题和子标题的数量将动态变化。 任何人都可以告诉我如何做到这一点。