You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XSSFPivotTable.java 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.xssf.usermodel;
  16. import org.apache.poi.ooxml.POIXMLDocumentPart;
  17. import org.apache.poi.openxml4j.opc.PackagePart;
  18. import org.apache.poi.ss.SpreadsheetVersion;
  19. import org.apache.poi.ss.usermodel.DataConsolidateFunction;
  20. import org.apache.poi.ss.usermodel.DataFormat;
  21. import org.apache.poi.ss.usermodel.Sheet;
  22. import org.apache.poi.ss.usermodel.Workbook;
  23. import org.apache.poi.ss.util.AreaReference;
  24. import org.apache.poi.ss.util.CellReference;
  25. import org.apache.poi.util.Beta;
  26. import org.apache.poi.util.Internal;
  27. import org.apache.poi.util.StringUtil;
  28. import org.apache.xmlbeans.XmlException;
  29. import org.apache.xmlbeans.XmlOptions;
  30. import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
  31. import javax.xml.namespace.QName;
  32. import java.io.IOException;
  33. import java.io.InputStream;
  34. import java.io.OutputStream;
  35. import java.util.ArrayList;
  36. import java.util.Collections;
  37. import java.util.List;
  38. import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
  39. public class XSSFPivotTable extends POIXMLDocumentPart {
  40. protected static final short CREATED_VERSION = 3;
  41. protected static final short MIN_REFRESHABLE_VERSION = 3;
  42. protected static final short UPDATED_VERSION = 3;
  43. private CTPivotTableDefinition pivotTableDefinition;
  44. private XSSFPivotCacheDefinition pivotCacheDefinition;
  45. private XSSFPivotCache pivotCache;
  46. private XSSFPivotCacheRecords pivotCacheRecords;
  47. private Sheet parentSheet;
  48. private Sheet dataSheet;
  49. @Beta
  50. protected XSSFPivotTable() {
  51. super();
  52. pivotTableDefinition = CTPivotTableDefinition.Factory.newInstance();
  53. pivotCache = new XSSFPivotCache();
  54. pivotCacheDefinition = new XSSFPivotCacheDefinition();
  55. pivotCacheRecords = new XSSFPivotCacheRecords();
  56. }
  57. /**
  58. * Creates an XSSFPivotTable representing the given package part and relationship.
  59. * Should only be called when reading in an existing file.
  60. *
  61. * @param part - The package part that holds xml data representing this pivot table.
  62. *
  63. * @since POI 3.14-Beta1
  64. */
  65. @Beta
  66. protected XSSFPivotTable(PackagePart part) throws IOException {
  67. super(part);
  68. try (InputStream stream = part.getInputStream()) {
  69. readFrom(stream);
  70. }
  71. }
  72. @Beta
  73. public void readFrom(InputStream is) throws IOException {
  74. try {
  75. XmlOptions options = new XmlOptions(DEFAULT_XML_OPTIONS);
  76. //Removing root element
  77. options.setLoadReplaceDocumentElement(null);
  78. pivotTableDefinition = CTPivotTableDefinition.Factory.parse(is, options);
  79. pivotCacheDefinition = null;
  80. } catch (XmlException e) {
  81. throw new IOException(e.getLocalizedMessage());
  82. }
  83. }
  84. private void lazyInitXSSFPivotCacheDefinition() {
  85. for (POIXMLDocumentPart documentPart : getRelations()) {
  86. if (documentPart instanceof XSSFPivotCacheDefinition) {
  87. pivotCacheDefinition = (XSSFPivotCacheDefinition) documentPart;
  88. break;
  89. }
  90. }
  91. }
  92. @Beta
  93. public void setPivotCache(XSSFPivotCache pivotCache) {
  94. this.pivotCache = pivotCache;
  95. }
  96. @Beta
  97. public XSSFPivotCache getPivotCache() {
  98. return pivotCache;
  99. }
  100. @Beta
  101. public Sheet getParentSheet() {
  102. return parentSheet;
  103. }
  104. @Beta
  105. public void setParentSheet(XSSFSheet parentSheet) {
  106. this.parentSheet = parentSheet;
  107. }
  108. @Beta
  109. @Internal
  110. public CTPivotTableDefinition getCTPivotTableDefinition() {
  111. return pivotTableDefinition;
  112. }
  113. @Beta
  114. @Internal
  115. public void setCTPivotTableDefinition(CTPivotTableDefinition pivotTableDefinition) {
  116. this.pivotTableDefinition = pivotTableDefinition;
  117. }
  118. @Beta
  119. public XSSFPivotCacheDefinition getPivotCacheDefinition() {
  120. if (pivotCacheDefinition == null) {
  121. lazyInitXSSFPivotCacheDefinition();
  122. }
  123. return pivotCacheDefinition;
  124. }
  125. @Beta
  126. public void setPivotCacheDefinition(XSSFPivotCacheDefinition pivotCacheDefinition) {
  127. this.pivotCacheDefinition = pivotCacheDefinition;
  128. }
  129. @Beta
  130. public XSSFPivotCacheRecords getPivotCacheRecords() {
  131. return pivotCacheRecords;
  132. }
  133. @Beta
  134. public void setPivotCacheRecords(XSSFPivotCacheRecords pivotCacheRecords) {
  135. this.pivotCacheRecords = pivotCacheRecords;
  136. }
  137. @Beta
  138. public Sheet getDataSheet() {
  139. return dataSheet;
  140. }
  141. @Beta
  142. private void setDataSheet(Sheet dataSheet) {
  143. this.dataSheet = dataSheet;
  144. }
  145. @Beta
  146. @Override
  147. protected void commit() throws IOException {
  148. XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
  149. //Sets the pivotTableDefinition tag
  150. xmlOptions.setSaveSyntheticDocumentElement(new QName(CTPivotTableDefinition.type.getName().
  151. getNamespaceURI(), "pivotTableDefinition"));
  152. PackagePart part = getPackagePart();
  153. try (OutputStream out = part.getOutputStream()) {
  154. pivotTableDefinition.save(out, xmlOptions);
  155. }
  156. }
  157. /**
  158. * Set default values for the table definition.
  159. */
  160. @Beta
  161. protected void setDefaultPivotTableDefinition() {
  162. //Not more than one until more created
  163. pivotTableDefinition.setMultipleFieldFilters(false);
  164. //Indentation increment for compact rows
  165. pivotTableDefinition.setIndent(0);
  166. //The pivot version which created the pivot cache set to default value
  167. pivotTableDefinition.setCreatedVersion(CREATED_VERSION);
  168. //Minimun version required to update the pivot cache
  169. pivotTableDefinition.setMinRefreshableVersion(MIN_REFRESHABLE_VERSION);
  170. //Version of the application which "updated the spreadsheet last"
  171. pivotTableDefinition.setUpdatedVersion(UPDATED_VERSION);
  172. //Titles shown at the top of each page when printed
  173. pivotTableDefinition.setItemPrintTitles(true);
  174. //Set autoformat properties
  175. pivotTableDefinition.setUseAutoFormatting(true);
  176. pivotTableDefinition.setApplyNumberFormats(false);
  177. pivotTableDefinition.setApplyWidthHeightFormats(true);
  178. pivotTableDefinition.setApplyAlignmentFormats(false);
  179. pivotTableDefinition.setApplyPatternFormats(false);
  180. pivotTableDefinition.setApplyFontFormats(false);
  181. pivotTableDefinition.setApplyBorderFormats(false);
  182. pivotTableDefinition.setCacheId(pivotCache.getCTPivotCache().getCacheId());
  183. pivotTableDefinition.setName("PivotTable"+pivotTableDefinition.getCacheId());
  184. pivotTableDefinition.setDataCaption("Values");
  185. //Set the default style for the pivot table
  186. CTPivotTableStyle style = pivotTableDefinition.addNewPivotTableStyleInfo();
  187. style.setName("PivotStyleLight16");
  188. style.setShowLastColumn(true);
  189. style.setShowColStripes(false);
  190. style.setShowRowStripes(false);
  191. style.setShowColHeaders(true);
  192. style.setShowRowHeaders(true);
  193. }
  194. protected AreaReference getPivotArea() {
  195. final Workbook wb = getDataSheet().getWorkbook();
  196. return getPivotCacheDefinition().getPivotArea(wb);
  197. }
  198. /**
  199. * Verify column index (relative to first column in pivot area) is within the
  200. * pivot area
  201. *
  202. * @param columnIndex
  203. * @throws IndexOutOfBoundsException
  204. */
  205. private void checkColumnIndex(int columnIndex) throws IndexOutOfBoundsException {
  206. AreaReference pivotArea = getPivotArea();
  207. int size = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol() + 1;
  208. if (columnIndex < 0 || columnIndex >= size) {
  209. throw new IndexOutOfBoundsException("Column Index: " + columnIndex + ", Size: " + size);
  210. }
  211. }
  212. /**
  213. * Add a row label using data from the given column.
  214. * @param columnIndex the index of the source column to be used as row label.
  215. * {@code columnIndex} is 0-based indexed and relative to the first column in the source.
  216. */
  217. @Beta
  218. public void addRowLabel(int columnIndex) {
  219. checkColumnIndex(columnIndex);
  220. AreaReference pivotArea = getPivotArea();
  221. final int lastRowIndex = pivotArea.getLastCell().getRow() - pivotArea.getFirstCell().getRow();
  222. CTPivotFields pivotFields = pivotTableDefinition.getPivotFields();
  223. CTPivotField pivotField = CTPivotField.Factory.newInstance();
  224. CTItems items = pivotField.addNewItems();
  225. pivotField.setAxis(STAxis.AXIS_ROW);
  226. pivotField.setShowAll(false);
  227. for (int i = 0; i <= lastRowIndex; i++) {
  228. items.addNewItem().setT(STItemType.DEFAULT);
  229. }
  230. items.setCount(items.sizeOfItemArray());
  231. pivotFields.setPivotFieldArray(columnIndex, pivotField);
  232. CTRowFields rowFields;
  233. if(pivotTableDefinition.getRowFields() != null) {
  234. rowFields = pivotTableDefinition.getRowFields();
  235. } else {
  236. rowFields = pivotTableDefinition.addNewRowFields();
  237. }
  238. rowFields.addNewField().setX(columnIndex);
  239. rowFields.setCount(rowFields.sizeOfFieldArray());
  240. }
  241. @Beta
  242. public List<Integer> getRowLabelColumns() {
  243. if (pivotTableDefinition.getRowFields() != null) {
  244. List<Integer> columnIndexes = new ArrayList<>();
  245. for (CTField f : pivotTableDefinition.getRowFields().getFieldArray()) {
  246. columnIndexes.add(f.getX());
  247. }
  248. return columnIndexes;
  249. } else {
  250. return Collections.emptyList();
  251. }
  252. }
  253. /**
  254. * Add a col label using data from the given column.
  255. * @param columnIndex the index of the source column to be used as row label.
  256. * {@code columnIndex} is 0-based indexed and relative to the first column in the source.
  257. * @param valueFormat format of column value (e.g. for date: "DD.MM.YYYY")
  258. */
  259. @Beta
  260. public void addColLabel(int columnIndex, String valueFormat) {
  261. checkColumnIndex(columnIndex);
  262. AreaReference pivotArea = getPivotArea();
  263. final int lastRowIndex = pivotArea.getLastCell().getRow() - pivotArea.getFirstCell().getRow();
  264. CTPivotFields pivotFields = pivotTableDefinition.getPivotFields();
  265. CTPivotField pivotField = CTPivotField.Factory.newInstance();
  266. CTItems items = pivotField.addNewItems();
  267. pivotField.setAxis(STAxis.AXIS_COL);
  268. pivotField.setShowAll(false);
  269. if (StringUtil.isNotBlank(valueFormat)) {
  270. DataFormat df = parentSheet.getWorkbook().createDataFormat();
  271. pivotField.setNumFmtId(df.getFormat(valueFormat));
  272. }
  273. for (int i = 0; i <= lastRowIndex; i++) {
  274. items.addNewItem().setT(STItemType.DEFAULT);
  275. }
  276. items.setCount(items.sizeOfItemArray());
  277. pivotFields.setPivotFieldArray(columnIndex, pivotField);
  278. CTColFields colFields;
  279. if(pivotTableDefinition.getColFields() != null) {
  280. colFields = pivotTableDefinition.getColFields();
  281. } else {
  282. colFields = pivotTableDefinition.addNewColFields();
  283. }
  284. colFields.addNewField().setX(columnIndex);
  285. colFields.setCount(colFields.sizeOfFieldArray());
  286. }
  287. /**
  288. * Add a col label using data from the given column.
  289. * @param columnIndex the index of the source column to be used as row label.
  290. * {@code columnIndex} is 0-based indexed and relative to the first column in the source.
  291. */
  292. @Beta
  293. public void addColLabel(int columnIndex) {
  294. addColLabel(columnIndex, null);
  295. }
  296. @Beta
  297. public List<Integer> getColLabelColumns() {
  298. if (pivotTableDefinition.getColFields() != null) {
  299. List<Integer> columnIndexes = new ArrayList<>();
  300. for (CTField f : pivotTableDefinition.getColFields().getFieldArray()) {
  301. columnIndexes.add(f.getX());
  302. }
  303. return columnIndexes;
  304. } else {
  305. return Collections.emptyList();
  306. }
  307. }
  308. /**
  309. * Add a column label using data from the given column and specified function
  310. * @param columnIndex the index of the source column to be used as column label.
  311. * {@code columnIndex} is 0-based indexed and relative to the first column in the source.
  312. * @param function the function to be used on the data
  313. * The following functions exists:
  314. * Sum, Count, Average, Max, Min, Product, Count numbers, StdDev, StdDevp, Var, Varp
  315. * @param valueFieldName the name of pivot table value field
  316. * @param valueFormat format of value field (e.g. "#,##0.00")
  317. */
  318. @Beta
  319. public void addColumnLabel(DataConsolidateFunction function, int columnIndex, String valueFieldName, String valueFormat) {
  320. checkColumnIndex(columnIndex);
  321. addDataColumn(columnIndex, true);
  322. addDataField(function, columnIndex, valueFieldName, valueFormat);
  323. // colfield should be added for the second one.
  324. if (pivotTableDefinition.getDataFields().getCount() == 2) {
  325. CTColFields colFields;
  326. if(pivotTableDefinition.getColFields() != null) {
  327. colFields = pivotTableDefinition.getColFields();
  328. } else {
  329. colFields = pivotTableDefinition.addNewColFields();
  330. }
  331. colFields.addNewField().setX(-2);
  332. colFields.setCount(colFields.sizeOfFieldArray());
  333. }
  334. }
  335. /**
  336. * Add a column label using data from the given column and specified function
  337. * @param columnIndex the index of the source column to be used as column label.
  338. * {@code columnIndex} is 0-based indexed and relative to the first column in the source.
  339. * @param function the function to be used on the data
  340. * The following functions exists:
  341. * Sum, Count, Average, Max, Min, Product, Count numbers, StdDev, StdDevp, Var, Varp
  342. * @param valueFieldName the name of pivot table value field
  343. */
  344. @Beta
  345. public void addColumnLabel(DataConsolidateFunction function, int columnIndex, String valueFieldName) {
  346. addColumnLabel(function, columnIndex, valueFieldName, null);
  347. }
  348. /**
  349. * Add a column label using data from the given column and specified function
  350. * @param columnIndex the index of the source column to be used as column label
  351. * {@code columnIndex} is 0-based indexed and relative to the first column in the source..
  352. * @param function the function to be used on the data
  353. * The following functions exists:
  354. * Sum, Count, Average, Max, Min, Product, Count numbers, StdDev, StdDevp, Var, Varp
  355. */
  356. @Beta
  357. public void addColumnLabel(DataConsolidateFunction function, int columnIndex) {
  358. addColumnLabel(function, columnIndex, function.getName(), null);
  359. }
  360. /**
  361. * Add data field with data from the given column and specified function.
  362. * @param function the function to be used on the data
  363. * The following functions exists:
  364. * Sum, Count, Average, Max, Min, Product, Count numbers, StdDev, StdDevp, Var, Varp
  365. * @param columnIndex the index of the column to be used as column label.
  366. * @param valueFieldName the name of pivot table value field
  367. */
  368. @Beta
  369. private void addDataField(DataConsolidateFunction function, int columnIndex, String valueFieldName, String valueFormat) {
  370. checkColumnIndex(columnIndex);
  371. CTDataFields dataFields;
  372. if(pivotTableDefinition.getDataFields() != null) {
  373. dataFields = pivotTableDefinition.getDataFields();
  374. } else {
  375. dataFields = pivotTableDefinition.addNewDataFields();
  376. }
  377. CTDataField dataField = dataFields.addNewDataField();
  378. dataField.setSubtotal(STDataConsolidateFunction.Enum.forInt(function.getValue()));
  379. dataField.setName(valueFieldName);
  380. dataField.setFld(columnIndex);
  381. if (StringUtil.isNotBlank(valueFormat)) {
  382. DataFormat df = parentSheet.getWorkbook().createDataFormat();
  383. dataField.setNumFmtId(df.getFormat(valueFormat));
  384. }
  385. dataFields.setCount(dataFields.sizeOfDataFieldArray());
  386. }
  387. /**
  388. * Add column containing data from the referenced area.
  389. * @param columnIndex the index of the column containing the data
  390. * @param isDataField true if the data should be displayed in the pivot table.
  391. */
  392. @Beta
  393. public void addDataColumn(int columnIndex, boolean isDataField) {
  394. checkColumnIndex(columnIndex);
  395. CTPivotFields pivotFields = pivotTableDefinition.getPivotFields();
  396. CTPivotField pivotField = CTPivotField.Factory.newInstance();
  397. pivotField.setDataField(isDataField);
  398. pivotField.setShowAll(false);
  399. pivotFields.setPivotFieldArray(columnIndex, pivotField);
  400. }
  401. /**
  402. * Add filter for the column with the corresponding index and cell value
  403. * @param columnIndex index of column to filter on
  404. */
  405. @Beta
  406. public void addReportFilter(int columnIndex) {
  407. checkColumnIndex(columnIndex);
  408. AreaReference pivotArea = getPivotArea();
  409. int lastRowIndex = pivotArea.getLastCell().getRow() - pivotArea.getFirstCell().getRow();
  410. // check and change row of location
  411. CTLocation location = pivotTableDefinition.getLocation();
  412. AreaReference destination = new AreaReference(location.getRef(), SpreadsheetVersion.EXCEL2007);
  413. if (destination.getFirstCell().getRow() < 2) {
  414. AreaReference newDestination = new AreaReference(new CellReference(2, destination.getFirstCell().getCol()), new CellReference(
  415. 3, destination.getFirstCell().getCol()+1), SpreadsheetVersion.EXCEL2007);
  416. location.setRef(newDestination.formatAsString());
  417. }
  418. CTPivotFields pivotFields = pivotTableDefinition.getPivotFields();
  419. CTPivotField pivotField = CTPivotField.Factory.newInstance();
  420. CTItems items = pivotField.addNewItems();
  421. pivotField.setAxis(STAxis.AXIS_PAGE);
  422. pivotField.setShowAll(false);
  423. for(int i = 0; i <= lastRowIndex; i++) {
  424. items.addNewItem().setT(STItemType.DEFAULT);
  425. }
  426. items.setCount(items.sizeOfItemArray());
  427. pivotFields.setPivotFieldArray(columnIndex, pivotField);
  428. CTPageFields pageFields;
  429. if (pivotTableDefinition.getPageFields()!= null) {
  430. pageFields = pivotTableDefinition.getPageFields();
  431. //Another filter has already been created
  432. pivotTableDefinition.setMultipleFieldFilters(true);
  433. } else {
  434. pageFields = pivotTableDefinition.addNewPageFields();
  435. }
  436. CTPageField pageField = pageFields.addNewPageField();
  437. pageField.setHier(-1);
  438. pageField.setFld(columnIndex);
  439. pageFields.setCount(pageFields.sizeOfPageFieldArray());
  440. pivotTableDefinition.getLocation().setColPageCount(pageFields.getCount());
  441. }
  442. /**
  443. * Creates cacheSource and workSheetSource for pivot table and sets the source reference as well assets the location of the pivot table
  444. * @param position Position for pivot table in sheet
  445. * @param sourceSheet Sheet where the source will be collected from
  446. * @param refConfig an configurator that knows how to configure pivot table references
  447. */
  448. @Beta
  449. protected void createSourceReferences(CellReference position, Sheet sourceSheet, PivotTableReferenceConfigurator refConfig){
  450. //Get cell one to the right and one down from position, add both to AreaReference and set pivot table location.
  451. AreaReference destination = new AreaReference(position, new CellReference(
  452. position.getRow()+1, position.getCol()+1), SpreadsheetVersion.EXCEL2007);
  453. CTLocation location;
  454. if(pivotTableDefinition.getLocation() == null) {
  455. location = pivotTableDefinition.addNewLocation();
  456. location.setFirstDataCol(1);
  457. location.setFirstDataRow(1);
  458. location.setFirstHeaderRow(1);
  459. } else {
  460. location = pivotTableDefinition.getLocation();
  461. }
  462. location.setRef(destination.formatAsString());
  463. pivotTableDefinition.setLocation(location);
  464. //Set source for the pivot table
  465. CTPivotCacheDefinition cacheDef = getPivotCacheDefinition().getCTPivotCacheDefinition();
  466. CTCacheSource cacheSource = cacheDef.addNewCacheSource();
  467. cacheSource.setType(STSourceType.WORKSHEET);
  468. CTWorksheetSource worksheetSource = cacheSource.addNewWorksheetSource();
  469. worksheetSource.setSheet(sourceSheet.getSheetName());
  470. setDataSheet(sourceSheet);
  471. refConfig.configureReference(worksheetSource);
  472. if (worksheetSource.getName() == null && worksheetSource.getRef() == null) throw new IllegalArgumentException("Pivot table source area reference or name must be specified.");
  473. }
  474. @Beta
  475. protected void createDefaultDataColumns() {
  476. CTPivotFields pivotFields;
  477. if (pivotTableDefinition.getPivotFields() != null) {
  478. pivotFields = pivotTableDefinition.getPivotFields();
  479. } else {
  480. pivotFields = pivotTableDefinition.addNewPivotFields();
  481. }
  482. AreaReference sourceArea = getPivotArea();
  483. int firstColumn = sourceArea.getFirstCell().getCol();
  484. int lastColumn = sourceArea.getLastCell().getCol();
  485. CTPivotField pivotField;
  486. for(int i = firstColumn; i<=lastColumn; i++) {
  487. pivotField = pivotFields.addNewPivotField();
  488. pivotField.setDataField(false);
  489. pivotField.setShowAll(false);
  490. }
  491. pivotFields.setCount(pivotFields.sizeOfPivotFieldArray());
  492. }
  493. protected static interface PivotTableReferenceConfigurator {
  494. /**
  495. * Configure the name or area reference for the pivot table
  496. * @param wsSource CTWorksheetSource that needs the pivot source reference assignment
  497. */
  498. public void configureReference(CTWorksheetSource wsSource);
  499. }
  500. }