【问题标题】:creating Pivot table in excel sheet using java使用java在excel工作表中创建数据透视表
【发布时间】:2017-02-15 16:50:58
【问题描述】:

如何使用 java.xml 在数据透视表中设置标题标题。 我必须使用 apache poi 在 excel 表中创建数据透视表。现在使用 java 更改行和列标题标签。

【问题讨论】:

    标签: java excel apache-poi pivot-table


    【解决方案1】:
    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(); 
            }
    }
    

    这可能会对您的问题有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-11
      • 1970-01-01
      • 2018-09-04
      • 2019-06-20
      • 2020-12-23
      • 2018-08-25
      • 1970-01-01
      相关资源
      最近更新 更多