溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

java中怎么利用poi導(dǎo)出excel透視表

發(fā)布時間:2021-06-11 16:24:50 來源:億速云 閱讀:602 作者:Leah 欄目:編程語言

這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)java中怎么利用poi導(dǎo)出excel透視表,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

代碼如下:

// 利用esaypoi生成excel數(shù)據(jù),即sheet1里面的數(shù)據(jù)
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(null, "sheet1", ExcelType.XSSF), pojoClass, list);
    Sheet sheet1 = workbook.getSheetAt(0);
    sheet1.setDefaultColumnWidth(50 * 256);
    sheet1.setDefaultRowHeight((short)(2 * 256));

    // 創(chuàng)建數(shù)據(jù)透視sheet
    XSSFSheet pivotSheet = (XSSFSheet )workbook.createSheet();
    pivotSheet.setDefaultColumnWidth(50 * 256);

    // 獲取數(shù)據(jù)sheet的總行數(shù)
    int num = sheet1.getLastRowNum();
    // 數(shù)據(jù)透視表數(shù)據(jù)源的起點單元格位置
    CellReference topLeft = new CellReference("A1");
    // 數(shù)據(jù)透視表數(shù)據(jù)源的終點單元格位置
    CellReference botRight = new CellReference(("M"+num));
    // 數(shù)據(jù)透視表生產(chǎn)的起點單元格位置
    CellReference ptStartCell = new CellReference("A1");
    AreaReference areaR = new AreaReference(topLeft, botRight);
    XSSFPivotTable pivotTable = pivotSheet.createPivotTable(areaR, ptStartCell, sheet1);
    // 添加行標(biāo)簽
    pivotTable.addRowLabel(4); // 部門
    pivotTable.addRowLabel(1); // 科目
    pivotTable.addRowLabel(0); // 借貸方向
    pivotTable.addRowLabel(11); // 單據(jù)編號
    pivotTable.addRowLabel(12); // 憑證編號
    pivotTable.addRowLabel(9); // 付款編碼
    pivotTable.addRowLabel(10); // 付款時間
    pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 3, "分錄金額");
    // 將透視表的列以表格的樣式顯示 這個地方弄了好久
    int count = 13; // count為數(shù)據(jù)源的列的數(shù)量
    for (int i = 0; i < count; i++) {
      CTPivotField ctPivotField = pivotTable.getCTPivotTableDefinition().getPivotFields().getPivotFieldArray(i);
      ctPivotField.setOutline(false);
    }

上述就是小編為大家分享的java中怎么利用poi導(dǎo)出excel透視表了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI