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.

TestCalculationChain.java 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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.model;
  16. import static org.junit.jupiter.api.Assertions.assertEquals;
  17. import java.io.IOException;
  18. import org.apache.poi.ss.usermodel.CellType;
  19. import org.apache.poi.xssf.XSSFTestDataSamples;
  20. import org.apache.poi.xssf.usermodel.XSSFCell;
  21. import org.apache.poi.xssf.usermodel.XSSFSheet;
  22. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  23. import org.junit.jupiter.api.Test;
  24. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcCell;
  25. public final class TestCalculationChain {
  26. @Test
  27. void test46535() throws IOException {
  28. try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("46535.xlsx")) {
  29. CalculationChain chain = wb.getCalculationChain();
  30. //the bean holding the reference to the formula to be deleted
  31. CTCalcCell c = chain.getCTCalcChain().getCArray(0);
  32. int cnt = chain.getCTCalcChain().sizeOfCArray();
  33. assertEquals(10, c.getI());
  34. assertEquals("E1", c.getR());
  35. XSSFSheet sheet = wb.getSheet("Test");
  36. XSSFCell cell = sheet.getRow(0).getCell(4);
  37. assertEquals(CellType.FORMULA, cell.getCellType());
  38. cell.setCellFormula(null);
  39. //the count of items is less by one
  40. c = chain.getCTCalcChain().getCArray(0);
  41. int cnt2 = chain.getCTCalcChain().sizeOfCArray();
  42. assertEquals(cnt - 1, cnt2);
  43. //the first item in the calculation chain is the former second one
  44. assertEquals(10, c.getI());
  45. assertEquals("C1", c.getR());
  46. assertEquals(CellType.STRING, cell.getCellType());
  47. cell.setCellValue("ABC");
  48. assertEquals(CellType.STRING, cell.getCellType());
  49. }
  50. }
  51. }