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-----------------------");
}

}

缺少Row的相关代码。

// 产生表格标题行
HSSFRow row = sheet.createRow(0);
for (int i = 0; i < list.size(); i++) {

            row = sheet.createRow(dataRowNum++); //创建行

看你的代码是想在外层循环是处理Excel的每一行,内存循环是每一列的信息。
Excel的结构是Sheet——>Row——>Cell。你应该在外层for循环中创建Row对象,添加该Row到Sheet上,内层循环的addCell是添加到Row对象上。
祝好!

你的内层循环rate = new Number(0,line, douRate);都是操作的第一行。
应该是rate = new Number(i,line, douRate);
你修改试试!祝好!

楼上说的都需要确认,另外jxl的包应还在维护吗?我都换成Apache POI了。