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.

TestXSSFPivotTableRef.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.ss.usermodel.Cell;
  17. import org.apache.poi.ss.usermodel.Row;
  18. import org.apache.poi.ss.util.AreaReference;
  19. import org.apache.poi.ss.util.CellReference;
  20. import org.junit.jupiter.api.BeforeEach;
  21. /**
  22. * Test pivot tables created by area reference
  23. */
  24. class TestXSSFPivotTableRef extends BaseTestXSSFPivotTable {
  25. @Override
  26. @BeforeEach
  27. protected void setUp(){
  28. wb = new XSSFWorkbook();
  29. XSSFSheet sheet = wb.createSheet();
  30. Row row1 = sheet.createRow(0);
  31. // Create a cell and put a value in it.
  32. Cell cell = row1.createCell(0);
  33. cell.setCellValue("Names");
  34. Cell cell2 = row1.createCell(1);
  35. cell2.setCellValue("#");
  36. Cell cell7 = row1.createCell(2);
  37. cell7.setCellValue("Data");
  38. Cell cell10 = row1.createCell(3);
  39. cell10.setCellValue("Value");
  40. Row row2 = sheet.createRow(1);
  41. Cell cell3 = row2.createCell(0);
  42. cell3.setCellValue("Jan");
  43. Cell cell4 = row2.createCell(1);
  44. cell4.setCellValue(10);
  45. Cell cell8 = row2.createCell(2);
  46. cell8.setCellValue("Apa");
  47. Cell cell11 = row1.createCell(3);
  48. cell11.setCellValue(11.11);
  49. Row row3 = sheet.createRow(2);
  50. Cell cell5 = row3.createCell(0);
  51. cell5.setCellValue("Ben");
  52. Cell cell6 = row3.createCell(1);
  53. cell6.setCellValue(9);
  54. Cell cell9 = row3.createCell(2);
  55. cell9.setCellValue("Bepa");
  56. Cell cell12 = row1.createCell(3);
  57. cell12.setCellValue(12.12);
  58. AreaReference source = wb.getCreationHelper().createAreaReference("A1:C2");
  59. pivotTable = sheet.createPivotTable(source, new CellReference("H5"));
  60. XSSFSheet offsetSheet = wb.createSheet();
  61. Row tableRow_1 = offsetSheet.createRow(1);
  62. offsetOuterCell = tableRow_1.createCell(1);
  63. offsetOuterCell.setCellValue(-1);
  64. Cell tableCell_1_1 = tableRow_1.createCell(2);
  65. tableCell_1_1.setCellValue("Row #");
  66. Cell tableCell_1_2 = tableRow_1.createCell(3);
  67. tableCell_1_2.setCellValue("Exponent");
  68. Cell tableCell_1_3 = tableRow_1.createCell(4);
  69. tableCell_1_3.setCellValue("10^Exponent");
  70. Row tableRow_2 = offsetSheet.createRow(2);
  71. Cell tableCell_2_1 = tableRow_2.createCell(2);
  72. tableCell_2_1.setCellValue(0);
  73. Cell tableCell_2_2 = tableRow_2.createCell(3);
  74. tableCell_2_2.setCellValue(0);
  75. Cell tableCell_2_3 = tableRow_2.createCell(4);
  76. tableCell_2_3.setCellValue(1);
  77. Row tableRow_3= offsetSheet.createRow(3);
  78. Cell tableCell_3_1 = tableRow_3.createCell(2);
  79. tableCell_3_1.setCellValue(1);
  80. Cell tableCell_3_2 = tableRow_3.createCell(3);
  81. tableCell_3_2.setCellValue(1);
  82. Cell tableCell_3_3 = tableRow_3.createCell(4);
  83. tableCell_3_3.setCellValue(10);
  84. Row tableRow_4 = offsetSheet.createRow(4);
  85. Cell tableCell_4_1 = tableRow_4.createCell(2);
  86. tableCell_4_1.setCellValue(2);
  87. Cell tableCell_4_2 = tableRow_4.createCell(3);
  88. tableCell_4_2.setCellValue(2);
  89. Cell tableCell_4_3 = tableRow_4.createCell(4);
  90. tableCell_4_3.setCellValue(100);
  91. AreaReference offsetSource = wb.getCreationHelper().createAreaReference(
  92. new CellReference("C2"), new CellReference("E4"));
  93. offsetPivotTable = offsetSheet.createPivotTable(offsetSource, new CellReference("C6"));
  94. }
  95. }