真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

json數(shù)組怎樣導(dǎo)出到Excel

本篇文章給大家分享的是有關(guān)json數(shù)組怎樣導(dǎo)出到Excel,小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

創(chuàng)新互聯(lián)IDC提供業(yè)務(wù):綿陽服務(wù)器托管,成都服務(wù)器租用,綿陽服務(wù)器托管,重慶服務(wù)器租用等四川省內(nèi)主機(jī)托管與主機(jī)租用業(yè)務(wù);數(shù)據(jù)中心含:雙線機(jī)房,BGP機(jī)房,電信機(jī)房,移動機(jī)房,聯(lián)通機(jī)房。

導(dǎo)出方法

public static JSONObject createExcel(String src, JSONArray json) {
        //用于返回響應(yīng)的消息
        JSONObject result = new JSONObject();
        try {
            File file = new File(src);
            file.createNewFile();
            OutputStream outputStream = new FileOutputStream(file);
            WritableWorkbook writableWorkbook = Workbook.createWorkbook(outputStream);
            WritableSheet sheet = writableWorkbook.createSheet("First sheet", 0);
            //設(shè)置邊框
            WritableFont font = new WritableFont(WritableFont.TIMES, 10, WritableFont.NO_BOLD, false);
            WritableCellFormat format = new WritableCellFormat(font);
            format.setBorder(jxl.format.Border.ALL, BorderLineStyle.THIN);
            format.setAlignment(Alignment.CENTRE);
            JSONArray jsonArray = json;
            Label label;//單元格對象
            int column = 0;//列數(shù)計數(shù)
            JSONObject first = jsonArray.getJSONObject(0);
            Iterator iterator = first.keys();
            while (iterator.hasNext()) {
                String key = iterator.next();
                label = new Label(column++, 0, key, format);
                sheet.addCell(label);
            }
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject item = jsonArray.getJSONObject(i);
                iterator = item.keys();
                column = 0;
                while (iterator.hasNext()) {
                    String key = iterator.next();
                    String value = item.getString(key);
                    label = new Label(column++, (i + 1), value, format);
                    sheet.addCell(label);
                }
            }
            writableWorkbook.write();
            writableWorkbook.close();
        } catch (Exception e) {
            result.put("result", "failed");
            result.put("reason", e.getMessage());
            return result;
        }
        result.put("result", "successed");
        return result;
    }

測試方法

public static void main(String[] args) {
        String src = "C:\\a.xls";
        String str = "[{\"dupCount\":4,\"qs_sumValue\":30,\"qs_span\":16,\"qs_dupCount\":0,\"sumValue\":64,\"dxb\":\"2:6\",\"job_qs\":\"2:1\",\"winNumber\":\"19 03 08 06 12 01 05 10\",\"zhb\":\"4:4\",\"matchNo\":\"17122387\",\"zhb_qs\":\"2:1\",\"job\":\"4:4\",\"dxb_qs\":\"1:2\",\"span\":18},{\"dupCount\":4,\"qs_sumValue\":36,\"qs_span\":14,\"qs_dupCount\":1,\"sumValue\":70,\"dxb\":\"3:5\",\"job_qs\":\"0:3\",\"winNumber\":\"20 10 06 11 15 01 02 05\",\"zhb\":\"4:4\",\"matchNo\":\"17122386\",\"zhb_qs\":\"0:3\",\"job\":\"4:4\",\"dxb_qs\":\"1:2\",\"span\":19},{\"dupCount\":5,\"qs_sumValue\":32,\"qs_span\":13,\"qs_dupCount\":0,\"sumValue\":57,\"dxb\":\"1:7\",\"job_qs\":\"2:1\",\"winNumber\":\"19 07 06 10 01 02 03 09\",\"zhb\":\"5:3\",\"matchNo\":\"17122385\",\"zhb_qs\":\"2:1\",\"job\":\"5:3\",\"dxb_qs\":\"1:2\",\"span\":18},{\"dupCount\":6,\"qs_sumValue\":15,\"qs_span\":10,\"qs_dupCount\":1,\"sumValue\":46,\"dxb\":\"1:7\",\"job_qs\":\"3:0\",\"winNumber\":\"11 01 03 08 10 02 05 06\",\"zhb\":\"5:3\",\"matchNo\":\"17122384\",\"zhb_qs\":\"3:0\",\"job\":\"4:4\",\"dxb_qs\":\"1:2\",\"span\":10},{\"dupCount\":0,\"qs_sumValue\":27,\"qs_span\":5,\"qs_dupCount\":0,\"sumValue\":46,\"dxb\":\"1:7\",\"job_qs\":\"1:2\",\"winNumber\":\"10 11 06 04 05 01 02 07\",\"zhb\":\"5:3\",\"matchNo\":\"17122383\",\"zhb_qs\":\"1:2\",\"job\":\"4:4\",\"dxb_qs\":\"1:2\",\"span\":10}]";
        JSONArray jsonArray = JSONArray.fromObject(str);
        JSONObject jsonObject1 = createExcel(src, jsonArray);
        if (!JSONUtils.isNull(jsonObject1.get("result"))) {
            String result = jsonObject1.get("result").toString();
            if ("failed".equals(result)) {
                System.out.println(jsonObject1.get("reason"));
            }
        }
    }

以上就是json數(shù)組怎樣導(dǎo)出到Excel,小編相信有部分知識點(diǎn)可能是我們?nèi)粘9ぷ鲿姷交蛴玫降?。希望你能通過這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。


當(dāng)前文章:json數(shù)組怎樣導(dǎo)出到Excel
標(biāo)題鏈接:http://weahome.cn/article/ggpsss.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部