In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to write the code of excel PivotTable exported by java based on poi, the content of the article is of high quality, so the editor shares it for you to do a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
This article mainly introduces the code example of excel PivotTable exported by java based on poi, which is introduced in detail through the sample code, which has a certain reference value for everyone's study or work. Friends who need it can refer to it.
Once upon a time, I was a front-end programmer, with the dream of getting through the post (former) governor (back) two (open) pulse (hair) turned to the back end, self-taught two weeks Java + spring family bucket, directly on the project combat. Recently received a demand: export business data to a PivotTable.
Demand development has been completed for some time, Party A's uncles and aunts, grandparents are also very happy, I am also very happy, so I thought that we can not learn in vain, so write this essay.
First, take a look at the excel effect image exported with easypoi+POI (easypoi is used to export sheet1 data sources, and poi is used to sheet0 PivotTable):
The excel in the figure is divided into two sheet, sheet1 is the data source, and sheet0 is the PivotTable generated from the data of sheet. The code is as follows:
/ / use esaypoi to generate excel data, that is, data in sheet1 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); / / create Pivotsheet XSSFSheet pivotSheet = (XSSFSheet) workbook.createSheet (); pivotSheet.setDefaultColumnWidth (50 * 256) / / get the total number of rows of the data sheet int num = sheet1.getLastRowNum (); / / the starting cell location of the PivotTable data source CellReference topLeft = new CellReference ("A1"); / / the end cell location of the PivotTable data source CellReference botRight = new CellReference (("M" + num)); / / the starting cell location of the PivotTable production CellReference ptStartCell = new CellReference ("A1"); AreaReference areaR = new AreaReference (topLeft, botRight) XSSFPivotTable pivotTable = pivotSheet.createPivotTable (areaR, ptStartCell, sheet1); / / add line label pivotTable.addRowLabel (4); / / departmental pivotTable.addRowLabel (1); / / subject pivotTable.addRowLabel (0); / / loan direction pivotTable.addRowLabel (11); / / document number pivotTable.addRowLabel (12); / / voucher number pivotTable.addRowLabel (9); / / payment code pivotTable.addRowLabel (10) / / payment time pivotTable.addColumnLabel (DataConsolidateFunction.SUM, 3, "entry amount"); / / display the columns of the PivotTable in the form of a table for a long time int count = 13; / / the number of columns with count as the data source for (int I = 0; I < count; itemized +) {CTPivotField ctPivotField = pivotTable.getCTPivotTableDefinition (). GetPivotFields (). GetPivotFieldArray (I); ctPivotField.setOutline (false);}
On java poi-based export of excel PivotTable code how to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.