簡體   English   中英

使用java在excel表中創建數據透視表

[英]creating Pivot table in excel sheet using java

如何使用java在數據透視表中設置標題標題。 我必須使用 apache poi.Now 在 Excel 表中創建數據透視表以使用 java 更改行和列標題標簽。

import java.io.FileOutputStream;
import java.io.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.*;
import org.apache.poi.xssf.usermodel.*;
public class readxlsx {  
        public static void main(String[] args) throws Exception{
                /* Read the input file that contains the data to pivot */
                FileInputStream input_document = new FileInputStream(new File("inputFile.xlsx"));    
                /* Create a POI XSSFWorkbook Object from the input file */
                XSSFWorkbook my_xlsx_workbook = new XSSFWorkbook(input_document); 
                /* Read Data to be Pivoted - we have only one worksheet */
                XSSFSheet sheet = my_xlsx_workbook.getSheetAt(0); 
                /* Get the reference for Pivot Data */
                AreaReference a=new AreaReference("A1:C51");
                /* Find out where the Pivot Table needs to be placed */
                CellReference b=new CellReference("I5");
                /* Create Pivot Table */
                XSSFPivotTable pivotTable = sheet.createPivotTable(a,b);
                /* Add filters */
                pivotTable.addReportFilter(0);
                pivotTable.addRowLabel(1);
                pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 2); 
                /* Write Pivot Table to File */
                FileOutputStream output_file = new FileOutputStream(new File("POI_XLS_Pivot_Example.xlsx")); 
                my_xlsx_workbook.write(output_file);
                input_document.close(); 
        }
}

這可能會幫助您解決問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM