第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

無(wú)法使用 apache poi 4.0.1 創(chuàng)建數(shù)據(jù)透視表

無(wú)法使用 apache poi 4.0.1 創(chuàng)建數(shù)據(jù)透視表

翻閱古今 2022-07-14 16:26:52
我們正在嘗試基于我們以編程方式創(chuàng)建的 .xlsx 文件生成數(shù)據(jù)透視表。      FileInputStream input_document = new FileInputStream(new File("testme.xlsx"));    XSSFWorkbook wb = new XSSFWorkbook(input_document);    XSSFSheet pivotSheet = wb.createSheet("Pivot sheet");    //create pivot table     XSSFPivotTable pivotTable = pivotSheet.createPivotTable(            new AreaReference(new CellReference("\'Selected Messages\'!A3"), new CellReference("\'Selected Messages\'!T4620"), //make the reference big enough for later data                    SpreadsheetVersion.EXCEL2007),            new CellReference("\'Pivot sheet\'!C5"), wb.getSheet("Selected Messages"));    //Configure the pivot table    //Use first column as row label    pivotTable.addRowLabel(0);    pivotTable.addRowLabel(2);    pivotTable.addColumnLabel(DataConsolidateFunction.COUNT, 5, "Number of messages");    pivotTable.addColLabel(4);    pivotTable.addReportFilter(11);    wb.write(new FileOutputStream("SXSSFPivotTableTest.xlsx"));    wb.close();這是我們使用的代碼示例。testme.xlsx是我們制作的文件,里面有很多數(shù)據(jù)。數(shù)據(jù)在Selected Messagesheet里面。我們想從這些數(shù)據(jù)創(chuàng)建一個(gè)數(shù)據(jù)透視表,在同一個(gè)文件的一個(gè)新工作表中,然后創(chuàng)建一個(gè)包含所有工作表的新文件。我們的問(wèn)題是,在創(chuàng)建后,當(dāng)我們嘗試打開(kāi)新文件時(shí),Excel 會(huì)嘗試恢復(fù)它,但它會(huì)刪除數(shù)據(jù)透視表和所有負(fù)責(zé)它的 .xml 文件。我們得到的錯(cuò)誤信息如下所示:已刪除功能:來(lái)自 /xl/pivotCache/pivotCacheDefinition1.xml 部分(數(shù)據(jù)透視表緩存)的數(shù)據(jù)透視表報(bào)告 已刪除功能:來(lái)自 /xl/pivotTables/pivotTable1.xml 部分(數(shù)據(jù)透視表視圖)的數(shù)據(jù)透視表報(bào)告 已刪除記錄:來(lái)自 /xl/workbook.xml 的工作簿屬性部分(工作簿)在任何以前的版本或最新版本中是否有人有同樣的問(wèn)題?任何解決方案可以幫助我們克服我們的問(wèn)題?注意生成的 .xlsx 可以用 LibreOffice 打開(kāi)。標(biāo)題是 Type,MRN or Correl ID,From,Sent To,Received,CoA,CoD,Exp,Exc,Size,Type Error,Pointer,Reason,Original Value,Action by recipient,Interchange Error code,Rejected Msg,Action by recipient2,Error code
查看完整描述

1 回答

?
慕仙森

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊

我找到了解決這個(gè)問(wèn)題的方法。我們創(chuàng)建了一個(gè) CTTable ,類似于 Excel 中的表格格式按鈕,然后創(chuàng)建了數(shù)據(jù)透視表。下面是示例。將生成的文件提供給上面發(fā)布的代碼,并生成最終的 .xlsx 文件。


    FileInputStream input_document = new FileInputStream(new File("testme.xlsx"));

    XSSFWorkbook my_xlsx_workbook = new XSSFWorkbook(input_document);

    XSSFSheet sheet = my_xlsx_workbook.getSheetAt(0);

    XSSFTable my_table = sheet.createTable();


    CTTable cttable = my_table.getCTTable();

    CTTableStyleInfo table_style = cttable.addNewTableStyleInfo();

    table_style.setName("TableStyleMedium9");

    table_style.setShowColumnStripes(true);

    table_style.setShowRowStripes(true);

    AreaReference my_data_range = new AreaReference(new CellReference(9, 0), new CellReference(18, 19), SpreadsheetVersion.EXCEL2007);

    cttable.setRef(my_data_range.formatAsString());

    cttable.setDisplayName("MYTABLE");      /* this is the display name of the table */

    cttable.setName("Test");    /* This maps to "displayName" attribute in <table>, OOXML */

    cttable.setId(1L); //id attribute against table as long value

    for(int x = my_xlsx_workbook.getSheetAt(0).getRow(2).getRowNum();x < my_xlsx_workbook.getSheetAt(0).getLastRowNum(); x++) {

        //add columns for each row

        CTTableColumns columns = cttable.addNewTableColumns();

        //define number of columns for each row

        columns.setCount(my_xlsx_workbook.getSheetAt(0).getRow(x).getLastCellNum());

        //loop the columns to add value and id

        for (int i = 0; i < my_xlsx_workbook.getSheetAt(0).getRow(x).getLastCellNum(); i++) {

            CTTableColumn column = columns.addNewTableColumn();

            column.setName(my_xlsx_workbook.getSheetAt(0).getRow(x).getCell(i).getStringCellValue());

            column.setId(my_xlsx_workbook.getSheetAt(0).getRow(x).getCell(i).getColumnIndex() + i);

        }

        //add each row into the table

        cttable.setTableColumns(columns);

    }

    sheet.setAutoFilter(new CellRangeAddress(2,2,0,19));


    /* Write output as File */

    FileOutputStream fileOut = new FileOutputStream("Excel_Format_As_Table.xlsx");

    my_xlsx_workbook.write(fileOut);

    fileOut.close();

}


查看完整回答
反對(duì) 回復(fù) 2022-07-14
  • 1 回答
  • 0 關(guān)注
  • 287 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)