QingCheng11
2015-04-13 14:27
采纳率: 50%
浏览 1.8k
已采纳

JXL 在java中 为什 这样写了导出的excel只有一行

public class Test {

public static void main(String[] args) throws Exception{
    JSONObject jsonObject;// json类数据,
    int line = 0;

    Date d = new Date();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
    WritableWorkbook workbook = Workbook.createWorkbook(new File("F:/test/commentEXL"+dateFormat.format(d)+".xls"));
    //生成名为“第一页”的工作表,参数0表示这是第一页


    String htmlUrl = "http://apk.hiapk.com/appinfo/com.tencent.mm";
    Document doc = Jsoup.connect(htmlUrl).get();
    Elements eleHidAppId = doc.select("div#webInnerContent>div>div.detail_left>input#hidAppId");
    Elements eleHidAppName = doc.select("div#webInnerContent>div>div.detail_left>input#hidAppName");



    WritableSheet sheet= workbook.createSheet(eleHidAppName.val().toString(),0);
    String strHidAppId = eleHidAppId.val().toString();
    System.out.println(strHidAppId);
    double douRate;Number rate;
    for (int i = 1;i<=10; i++) {

        Document documentComment = Jsoup.connect(
                "http://apk.hiapk.com/web/api.do?qt=1701&id=" + strHidAppId+ "&pi=" + i + "&ps=10").get();
        Elements eleComment = documentComment.select("body");

        if (eleComment.text().isEmpty())
            break;

        jsonObject = new JSONObject(eleComment.text());//把获取的json型数据赋给jsonObject
        JSONArray jsonArray = jsonObject.getJSONArray("data");//提取data

        for (int j = 0; j < jsonArray.length(); j++) {
            JSONObject jsonComment = jsonArray.getJSONObject(j);            
            String strComment = jsonComment.getString("content");
            douRate = Double.valueOf(jsonComment.getString("rating"));  
            rate = new Number(0,line, douRate);
            Label label = new Label(1,line,strComment);
            line++;
            sheet.addCell(rate);
            sheet.addCell(label);
            workbook.write();
        System.out.println(douRate + "   " + strComment);
        }      
    }
    workbook.close();
    System.out
            .println("--------------------End Loading-----------------------");
}

}

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

4条回答 默认 最新

相关推荐 更多相似问题