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.

TestSXSSFBugs.java 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 static org.junit.Assert.assertEquals;
  17. import static org.junit.Assert.assertNotNull;
  18. import static org.junit.Assert.fail;
  19. import java.io.IOException;
  20. import org.apache.poi.ss.ITestDataProvider;
  21. import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues;
  22. import org.apache.poi.ss.usermodel.Cell;
  23. import org.apache.poi.ss.usermodel.CellType;
  24. import org.apache.poi.ss.usermodel.PrintSetup;
  25. import org.apache.poi.ss.usermodel.Row;
  26. import org.apache.poi.ss.usermodel.Sheet;
  27. import org.apache.poi.ss.usermodel.Workbook;
  28. import org.apache.poi.ss.util.CellRangeAddress;
  29. import org.apache.poi.xssf.SXSSFITestDataProvider;
  30. import org.apache.poi.xssf.XSSFITestDataProvider;
  31. import org.apache.poi.xssf.streaming.SXSSFWorkbook;
  32. import org.junit.Ignore;
  33. import org.junit.Test;
  34. public final class TestSXSSFBugs extends BaseTestBugzillaIssues {
  35. public TestSXSSFBugs() {
  36. super(SXSSFITestDataProvider.instance);
  37. }
  38. // override some tests which do not work for SXSSF
  39. @Override @Ignore("cloneSheet() not implemented") @Test public void bug18800() { /* cloneSheet() not implemented */ }
  40. @Override @Ignore("cloneSheet() not implemented") @Test public void bug22720() { /* cloneSheet() not implemented */ }
  41. @Override @Ignore("Evaluation is not fully supported") @Test public void bug47815() { /* Evaluation is not supported */ }
  42. @Override @Ignore("Evaluation is not fully supported") @Test public void bug46729_testMaxFunctionArguments() { /* Evaluation is not supported */ }
  43. @Override @Ignore("Reading data is not supported") @Test public void bug57798() { /* Reading data is not supported */ }
  44. /**
  45. * Setting repeating rows and columns shouldn't break
  46. * any print settings that were there before
  47. */
  48. @Test
  49. public void bug49253() throws Exception {
  50. Workbook wb1 = new SXSSFWorkbook();
  51. Workbook wb2 = new SXSSFWorkbook();
  52. CellRangeAddress cra = CellRangeAddress.valueOf("C2:D3");
  53. // No print settings before repeating
  54. Sheet s1 = wb1.createSheet();
  55. s1.setRepeatingColumns(cra);
  56. s1.setRepeatingRows(cra);
  57. PrintSetup ps1 = s1.getPrintSetup();
  58. assertEquals(false, ps1.getValidSettings());
  59. assertEquals(false, ps1.getLandscape());
  60. // Had valid print settings before repeating
  61. Sheet s2 = wb2.createSheet();
  62. PrintSetup ps2 = s2.getPrintSetup();
  63. ps2.setLandscape(false);
  64. assertEquals(true, ps2.getValidSettings());
  65. assertEquals(false, ps2.getLandscape());
  66. s2.setRepeatingColumns(cra);
  67. s2.setRepeatingRows(cra);
  68. ps2 = s2.getPrintSetup();
  69. assertEquals(true, ps2.getValidSettings());
  70. assertEquals(false, ps2.getLandscape());
  71. wb1.close();
  72. wb2.close();
  73. }
  74. // bug 60197: setSheetOrder should update sheet-scoped named ranges to maintain references to the sheets before the re-order
  75. @Test
  76. @Override
  77. public void bug60197_NamedRangesReferToCorrectSheetWhenSheetOrderIsChanged() throws Exception {
  78. try {
  79. super.bug60197_NamedRangesReferToCorrectSheetWhenSheetOrderIsChanged();
  80. } catch (final RuntimeException e) {
  81. final Throwable cause = e.getCause();
  82. //noinspection StatementWithEmptyBody
  83. if (cause instanceof IOException && cause.getMessage().equals("Stream closed")) {
  84. // expected on the second time that _testDataProvider.writeOutAndReadBack(SXSSFWorkbook) is called
  85. // if the test makes it this far, then we know that XSSFName sheet indices are updated when sheet
  86. // order is changed, which is the purpose of this test. Therefore, consider this a passing test.
  87. } else {
  88. throw e;
  89. }
  90. }
  91. }
  92. @Test
  93. public void bug61648() throws Exception {
  94. // works as expected
  95. writeWorkbook(new XSSFWorkbook(), "/tmp/61648.xlsx", XSSFITestDataProvider.instance);
  96. // does not work
  97. try {
  98. writeWorkbook(new SXSSFWorkbook(), "/tmp/61648s.xlsx", SXSSFITestDataProvider.instance);
  99. fail("Should catch exception here");
  100. } catch (RuntimeException e) {
  101. // this is not implemented yet
  102. }
  103. }
  104. void writeWorkbook(Workbook wb, String filename, ITestDataProvider testDataProvider) throws IOException {
  105. Sheet sheet = wb.createSheet("array formula test");
  106. int rowIndex = 0;
  107. int colIndex = 0;
  108. Row row = sheet.createRow(rowIndex++);
  109. Cell cell = row.createCell(colIndex++);
  110. cell.setCellType(CellType.STRING);
  111. cell.setCellValue("multiple");
  112. cell = row.createCell(colIndex++);
  113. cell.setCellType(CellType.STRING);
  114. cell.setCellValue("unique");
  115. writeRow(sheet, rowIndex++, 80d, "INDEX(A2:A7, MATCH(FALSE, ISBLANK(A2:A7), 0))");
  116. writeRow(sheet, rowIndex++, 30d, "IFERROR(INDEX(A2:A7, MATCH(1, (COUNTIF(B2:B2, A2:A7) = 0) * (NOT(ISBLANK(A2:A7))), 0)), \"\")");
  117. writeRow(sheet, rowIndex++, 30d, "IFERROR(INDEX(A2:A7, MATCH(1, (COUNTIF(B2:B3, A2:A7) = 0) * (NOT(ISBLANK(A2:A7))), 0)), \"\")");
  118. writeRow(sheet, rowIndex++, 2d, "IFERROR(INDEX(A2:A7, MATCH(1, (COUNTIF(B2:B4, A2:A7) = 0) * (NOT(ISBLANK(A2:A7))), 0)), \"\")");
  119. writeRow(sheet, rowIndex++, 30d, "IFERROR(INDEX(A2:A7, MATCH(1, (COUNTIF(B2:B5, A2:A7) = 0) * (NOT(ISBLANK(A2:A7))), 0)), \"\")");
  120. writeRow(sheet, rowIndex++, 2d, "IFERROR(INDEX(A2:A7, MATCH(1, (COUNTIF(B2:B6, A2:A7) = 0) * (NOT(ISBLANK(A2:A7))), 0)), \"\")");
  121. /*FileOutputStream fileOut = new FileOutputStream(filename);
  122. wb.write(fileOut);
  123. fileOut.close();*/
  124. Workbook wbBack = testDataProvider.writeOutAndReadBack(wb);
  125. assertNotNull(wbBack);
  126. wbBack.close();
  127. wb.close();
  128. }
  129. void writeRow(Sheet sheet, int rowIndex, Double col0Value, String col1Value) {
  130. int colIndex = 0;
  131. Row row = sheet.createRow(rowIndex);
  132. // numeric value cell
  133. Cell cell = row.createCell(colIndex++);
  134. cell.setCellType(CellType.NUMERIC);
  135. cell.setCellValue(col0Value);
  136. // formula value cell
  137. CellRangeAddress range = new CellRangeAddress(rowIndex, rowIndex, colIndex, colIndex);
  138. sheet.setArrayFormula(col1Value, range);
  139. }
  140. }