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++); //創建行