From 627105e288b7135c905d6724c0d9dd3ce77abc3b Mon Sep 17 00:00:00 2001
From: Yegor Kozlov
@@ -443,17 +458,21 @@ public class XSSFRow implements Row, Comparablenull
if the formula wasn't modified
*/
- private String shiftFormula(String formula, int n){
+ private String shiftFormula(String formula, FormulaShifter shifter){
XSSFSheet sheet = getSheet();
XSSFWorkbook wb = sheet.getWorkbook();
int sheetIndex = wb.getSheetIndex(sheet);
XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
Ptg[] ptgs = FormulaParser.parse(formula, fpb, FormulaType.CELL, sheetIndex);
- Ptg[] fmla = SharedFormulaRecord.convertSharedFormulas(ptgs, n, 0);
- return FormulaRenderer.toFormulaString(fpb, fmla);
+ String shiftedFmla = null;
+ if (shifter.adjustFormula(ptgs, sheetIndex)) {
+ shiftedFmla = FormulaRenderer.toFormulaString(fpb, ptgs);
+ }
+ return shiftedFmla;
}
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
index 90f920c3e7..e44208b75e 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
@@ -25,6 +25,7 @@ import javax.xml.namespace.QName;
import org.apache.poi.hssf.util.PaneInformation;
import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.record.formula.FormulaShifter;
import org.apache.poi.hssf.record.SharedFormulaRecord;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
@@ -60,7 +61,7 @@ import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelations
*
uDM1?fSHD&z-r3#OrWC)td>92#HvvH^-)=TdukG^i(*}^t%LY8F7mR?y zFhe@6-K1?-h?^;YU$o|>sr<9k_W|o!Nida1rat_+k94OMXe70d49gPB<2P;IecG!+ zA>vbZXF+}=^%m$(b+LTa+E7s@yHck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$jhukbHe!bcl6{y3GgCvCBXb8O`jn;4Vs^q!59ZTzaKvOwjrA4S z(Kd&BvKrmH=SW(2T)5{^m6p6Vvfe2P*O%c0$5RirB9ENu5@r`nL5U>ay4Fu`Y4(d> z%u+u&LH%8T>sKT_HsFCpgf|NC{s^#{iJh60wTX?x4|Z$DFFfs{#gpB~^g~U*tkj*~ zrQuN=$Y>V71eoqH;oU1qI^AXC5Io)cc0OogJa?43&{K@=bQ0TnI0E2Nx%6_=#@TmV zTi}DHC1p--yjVG~r_XAd&wTt!88=D~)Qdv;fc@@nRg!EA*{jv|eb}cQT$*z5Ie8`j zUVF&{P8dUz`V@cMgeB0mf+ __>lf{34U7|blnPPBMH2{f%jK7nm{1`BjXPm{&8e!s5_2x -)OQ#nG(v5xX?vfVZB3uTHWoD7Sn_GwtoyaHTsV@K(2~dZy(TUz_ZEBC zslcPYjG$<_2fc0bPgv{j_H=$e`as+(f}w$7k4 } cSR_Im?Nj9xRoGLOfwf zxKbM4HoXZ2&g2|qXQBa5Al&)kOjT07(W#Ald(&$t=TAhB_t;IIF@4d_?bq1qiXt5! zwjal+!(;;GarKFuhr3%iB6au|t0da#Vxn5;bc*^bRnJ$esK_OFfo?3{R-F?@a4qwQ zx`<^*e?2&fY8~eB_8qw*g-7oX(gP7V;3Dhy-;(?*$p5 <8{l^F z=of%0{=c98k5bZYl-m`CUnmfG6Xnl$_$$iKdc$p$+q>vrC}VI{{Tq~@d+OULx5fA` zlu>x`1CH_!X?`2wwwnEgFh>3d!oRicZP(j6>6dFAyrBet_}^61ZSTJ;ieJ6}KsOZt q@DF`)+x_n;;IHmla0T;k_dgSYnj$isr$6*MHUJE#I+*^)-Twinm6y2y literal 0 HcmV?d00001 diff --git a/src/testcases/org/apache/poi/hssf/data/SimpleMultiCell.xlsx b/src/testcases/org/apache/poi/hssf/data/SimpleMultiCell.xlsx new file mode 100755 index 0000000000000000000000000000000000000000..d5dfe7adc3eb0e8228713da69f653f467624c1ef GIT binary patch literal 8123 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e+95+zM z*de^_K6h7~fX*6>Bo4J_9=JA|1&pK$wvnhaX(P3U9*S``oWFb>zAv|4r=wvv=Kdv} z`1>}4AIyMbRoY+MnS61s0sUA4 C`jJ6D}M!auUn z)Y0)DGG5W}w+o)2X0ymg*tv^)N)x>k1FuPB>EU3R8ENOCQk;@_^;L{4i6!?%T3(ia zw}=w_+(kD-;T!GqEQR<6gs9{ueRfnf;Wu3#0W6VZo-LgHCch>mqX6>_@S=Hu3^kxL z cXu@Ef<9>@}ijop0m<;07R*7MlEy#%0Ugi>)JDruHf7|m-AKNEL zUB+uP6Rk7#&DPpe* |wiM~Iw+~fqJaWr1LF6f2k|x(ozYsfZ_JA&m##o1q!^;ah zK ifv4$ _C C_jYRuPA>m(?2l)02qpYe<|9(n*TYk{?VL> c@(<>}XIXV+bQDjn=7hL_k0@P$puYO_UvnYkkpKVy literal 0 HcmV?d00001 diff --git a/src/testcases/org/apache/poi/hssf/data/comments.xlsx b/src/testcases/org/apache/poi/hssf/data/comments.xlsx new file mode 100755 index 0000000000000000000000000000000000000000..d4e139853c2ddf39be6c6d565e867c4b44b4c018 GIT binary patch literal 10046 zcmeHNWmr^gw;mX3KtiOXyQQT;B$OIJ0qO1>I;4c5yFt1`32CI1?v_pwl %-(bDz3$n2J@ EChCGgunp+uaE$M zdw^*;4KawdgORm^j*_d5k-Zj+i 9Cf?~X(@0sBHu`3Y7#0B5A+Re%XN%;L_O8mEhv_n zV!QtiCA3mHS-EE(e{fGIgbgKI+!{S+6VR0xv+;IsX%Rs6hC8vG8R6t3U(X#>?;uCr z)&7xlQH1jim08exJf_9$=EZOs3;0B=0Bk6@qm=ri1>&&g=`JPe(&vj5WKrn3b0QXL z2v&jo2YFIw63BO?h9AcYx7UkF~?@x*ic6jqln&3_sN(tz50WqT@f; zSphv#FEN_oL@x0B+8(}NOofv3pl9f#4A10ZS|X2e3-l#gnv%9)c$0zi8t;5sCFy`p zEp2wsdVI*2u@i%R5CCv<0|Y4iEh?*&*{F_SRF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N@!RR1($u+ zD0mG@5#zVbcIYn>Scm5c^?C CQn0U@jF}$PN3d+50P % f| zSo|0^J^vc#kuSufV___O`XkQ&!a_Y8n}107oqm68DKYXEU)ZqPchD|KLbt fM|gugGb9u1K#he1 zg*%>Q6Lqh_qv4#AgZiHI7lT)##DMnH>r1I(MN5h(U>`4~E`@oP69dgOAt97A9>}CD z8%8moml~?P!Yn9$F)u>?zUx2( N=JN-=0{zx#}g>Yw9NKK1HgIG``+s)mY(w z8hc(}!JuD6e^FPn7?% mbBr!WfU+Ly=A+S_jEKs;sgFRjr#& zdFLi_IFJce`*mrfi$*904p5uGv%i24@rZ3{ 5WJX&OB#ZGK$yqpOmm&l4 z6FP)-5%fM|+ir9LuM5U$hjju=^V@)}T>?v%FPqL{cf|Q6L%d|D)((|gGZJ@rvXm{= z?_n^fyn(PZe73I-!}MQt0VRN|3c)_nJ6i?mMC(D{(%s3*-+(6{yB=OL9Lj$+y2O9k zl(^F1pJ2Di;Cc;rjt?7>KbQ;${{SYZe*YHDzees~``^4%qagElfWJ5V|7G}n9}f$U zzqJ2v8~(j}`d7p6jhO%3OTCSAyNC7@sSWm`(5;TzZR6X0pP$BH*fI-de7g&D8{l>o z?k4~&LH+CB|GS#pZNS^rl%Ih3*tY?HR ~ZR$`6@y8|C)G^(V?M-Vc=jw2ZwCbbCSY6X^5(A3(n>4{jseR^C4m>InZp__q$f zZF*bW{WOgx{$ctzsdwA@@51G$EdX#x0s#CXV{V)OJ>&e<{3ZEc%>T?k3NnbW2>RYp P#sn 505`>+23fK?_4 literal 0 HcmV?d00001 diff --git a/src/testcases/org/apache/poi/hssf/usermodel/BaseTestSheetShiftRows.java b/src/testcases/org/apache/poi/hssf/usermodel/BaseTestSheetShiftRows.java deleted file mode 100755 index 5c6716c7f4..0000000000 --- a/src/testcases/org/apache/poi/hssf/usermodel/BaseTestSheetShiftRows.java +++ /dev/null @@ -1,285 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hssf.usermodel; - -import junit.framework.TestCase; - -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; - -/** - * Tests row shifting capabilities (common base class for HSSF and XSSF tests). - * - * - * @author Shawn Laubach (slaubach at apache dot com) - * @author Toshiaki Kamoshida (kamoshida.toshiaki at future dot co dot jp) - */ -public abstract class BaseTestSheetShiftRows extends TestCase { - /** - * Override to provide HSSF / XSSF specific way for re-serialising a workbook - */ - protected abstract Workbook writeOutAndReadBack(Workbook wb); - /** - * Override to provide way of loading HSSF / XSSF sample workbooks - * @param sampleFileName without the ".xls" or ".xlsx" suffix - */ - protected abstract Workbook openSampleWorkbook(String sampleFileName); - /** - * Override to provide way of creating HSSF / XSSF workbooks - */ - protected abstract Workbook createWorkbook(); - - /** - * Tests the shiftRows function. Does three different shifts. - * After each shift, writes the workbook to file and reads back to - * check. This ensures that if some changes code that breaks - * writing or what not, they realize it. - * - * @author Shawn Laubach (slaubach at apache dot org) - */ - public final void testShiftRows(){ - final String sampleName = "SimpleMultiCell"; - // Read initial file in - Workbook wb = openSampleWorkbook(sampleName); - Sheet s = wb.getSheetAt( 0 ); - - // Shift the second row down 1 and write to temp file - s.shiftRows( 1, 1, 1 ); - - wb = writeOutAndReadBack(wb); - - // Read from temp file and check the number of cells in each - // row (in original file each row was unique) - s = wb.getSheetAt( 0 ); - - assertEquals(s.getRow(0).getPhysicalNumberOfCells(), 1); - confirmEmptyRow(s, 1); - assertEquals(s.getRow(2).getPhysicalNumberOfCells(), 2); - assertEquals(s.getRow(3).getPhysicalNumberOfCells(), 4); - assertEquals(s.getRow(4).getPhysicalNumberOfCells(), 5); - - // Shift rows 1-3 down 3 in the current one. This tests when - // 1 row is blank. Write to a another temp file - s.shiftRows( 0, 2, 3 ); - wb = writeOutAndReadBack(wb); - - // Read and ensure things are where they should be - s = wb.getSheetAt(0); - confirmEmptyRow(s, 0); - confirmEmptyRow(s, 1); - confirmEmptyRow(s, 2); - assertEquals(s.getRow(3).getPhysicalNumberOfCells(), 1); - confirmEmptyRow(s, 4); - assertEquals(s.getRow(5).getPhysicalNumberOfCells(), 2); - - // Read the first file again - wb = openSampleWorkbook(sampleName); - s = wb.getSheetAt( 0 ); - - // Shift rows 3 and 4 up and write to temp file - s.shiftRows( 2, 3, -2 ); - wb = writeOutAndReadBack(wb); - s = wb.getSheetAt( 0 ); - assertEquals(s.getRow(0).getPhysicalNumberOfCells(), 3); - assertEquals(s.getRow(1).getPhysicalNumberOfCells(), 4); - confirmEmptyRow(s, 2); - confirmEmptyRow(s, 3); - assertEquals(s.getRow(4).getPhysicalNumberOfCells(), 5); - } - private static void confirmEmptyRow(Sheet s, int rowIx) { - Row row = s.getRow(rowIx); - assertTrue(row == null || row.getPhysicalNumberOfCells() == 0); - } - - /** - * Tests when rows are null. - * - * @author Toshiaki Kamoshida (kamoshida.toshiaki at future dot co dot jp) - */ - public final void testShiftRow() { - Workbook b = createWorkbook(); - Sheet s = b.createSheet(); - s.createRow(0).createCell(0).setCellValue("TEST1"); - s.createRow(3).createCell(0).setCellValue("TEST2"); - s.shiftRows(0,4,1); - } - - /** - * Tests when shifting the first row. - * - * @author Toshiaki Kamoshida (kamoshida.toshiaki at future dot co dot jp) - */ - public final void testShiftRow0() { - Workbook b = createWorkbook(); - Sheet s = b.createSheet(); - s.createRow(0).createCell(0).setCellValue("TEST1"); - s.createRow(3).createCell(0).setCellValue("TEST2"); - s.shiftRows(0,4,1); - } - - /** - * When shifting rows, the page breaks should go with it - * - */ - public final void testShiftRowBreaks() { - Workbook b = createWorkbook(); - Sheet s = b.createSheet(); - Row row = s.createRow(4); - row.createCell(0).setCellValue("test"); - s.setRowBreak(4); - - s.shiftRows(4, 4, 2); - assertTrue("Row number 6 should have a pagebreak", s.isRowBroken(6)); - } - - - public final void testShiftWithComments() { - final String sampleName = "comments"; - Workbook wb = openSampleWorkbook(sampleName); - - Sheet sheet = wb.getSheet("Sheet1"); - assertEquals(3, sheet.getLastRowNum()); - - // Verify comments are in the position expected - assertNotNull(sheet.getCellComment(0,0)); - assertNull(sheet.getCellComment(1,0)); - assertNotNull(sheet.getCellComment(2,0)); - assertNotNull(sheet.getCellComment(3,0)); - - String comment1 = sheet.getCellComment(0,0).getString().getString(); - assertEquals(comment1,"comment top row1 (index0)\n"); - String comment3 = sheet.getCellComment(2,0).getString().getString(); - assertEquals(comment3,"comment top row3 (index2)\n"); - String comment4 = sheet.getCellComment(3,0).getString().getString(); - assertEquals(comment4,"comment top row4 (index3)\n"); - - // Shifting all but first line down to test comments shifting - sheet.shiftRows(1, sheet.getLastRowNum(), 1, true, true); - - // Test that comments were shifted as expected - assertEquals(4, sheet.getLastRowNum()); - assertNotNull(sheet.getCellComment(0,0)); - assertNull(sheet.getCellComment(1,0)); - assertNull(sheet.getCellComment(2,0)); - assertNotNull(sheet.getCellComment(3,0)); - assertNotNull(sheet.getCellComment(4,0)); - - String comment1_shifted = sheet.getCellComment(0,0).getString().getString(); - assertEquals(comment1,comment1_shifted); - String comment3_shifted = sheet.getCellComment(3,0).getString().getString(); - assertEquals(comment3,comment3_shifted); - String comment4_shifted = sheet.getCellComment(4,0).getString().getString(); - assertEquals(comment4,comment4_shifted); - - // Write out and read back in again - // Ensure that the changes were persisted - wb = writeOutAndReadBack(wb); - sheet = wb.getSheet("Sheet1"); - assertEquals(4, sheet.getLastRowNum()); - - // Verify comments are in the position expected after the shift - assertNotNull(sheet.getCellComment(0,0)); - assertNull(sheet.getCellComment(1,0)); - assertNull(sheet.getCellComment(2,0)); - assertNotNull(sheet.getCellComment(3,0)); - assertNotNull(sheet.getCellComment(4,0)); - - comment1_shifted = sheet.getCellComment(0,0).getString().getString(); - assertEquals(comment1,comment1_shifted); - comment3_shifted = sheet.getCellComment(3,0).getString().getString(); - assertEquals(comment3,comment3_shifted); - comment4_shifted = sheet.getCellComment(4,0).getString().getString(); - assertEquals(comment4,comment4_shifted); - } - - /** - * See bug #34023 - */ - public void testShiftWithFormulas() { - String sampleName = "ForShifting"; - Workbook wb = openSampleWorkbook(sampleName); - - Sheet sheet = wb.getSheet("Sheet1"); - assertEquals(20, sheet.getLastRowNum()); - - confirmRow(sheet, 0, 1, 171, 1, "ROW(D1)", "100+B1", "COUNT(D1:E1)"); - confirmRow(sheet, 1, 2, 172, 1, "ROW(D2)", "100+B2", "COUNT(D2:E2)"); - confirmRow(sheet, 2, 3, 173, 1, "ROW(D3)", "100+B3", "COUNT(D3:E3)"); - - confirmCell(sheet, 6, 1, 271, "200+B1"); - confirmCell(sheet, 7, 1, 272, "200+B2"); - confirmCell(sheet, 8, 1, 273, "200+B3"); - - confirmCell(sheet, 14, 0, 0.0, "A12"); // the cell referred to by this formula will be replaced - - // ----------- - // Row index 1 -> 11 (row "2" -> row "12") - sheet.shiftRows(1, 1, 10); - - // Now check what sheet looks like after move - - // no changes on row "1" - confirmRow(sheet, 0, 1, 171, 1, "ROW(D1)", "100+B1", "COUNT(D1:E1)"); - - // row "2" is now empty - assertEquals(0, sheet.getRow(1).getPhysicalNumberOfCells()); - - // Row "2" moved to row "12", and the formula has been updated. - // note however that the cached formula result (2) has not been updated. (POI differs from Excel here) - confirmRow(sheet, 11, 2, 172, 1, "ROW(D12)", "100+B12", "COUNT(D12:E12)"); - - // no changes on row "3" - confirmRow(sheet, 2, 3, 173, 1, "ROW(D3)", "100+B3", "COUNT(D3:E3)"); - - - confirmCell(sheet, 14, 0, 0.0, "#REF!"); - - - // Formulas on rows that weren't shifted: - confirmCell(sheet, 6, 1, 271, "200+B1"); - confirmCell(sheet, 7, 1, 272, "200+B12"); // this one moved - confirmCell(sheet, 8, 1, 273, "200+B3"); - - // check formulas on other sheets - Sheet sheet2 = wb.getSheet("Sheet2"); - confirmCell(sheet2, 0, 0, 371, "300+Sheet1!B1"); - confirmCell(sheet2, 1, 0, 372, "300+Sheet1!B12"); - confirmCell(sheet2, 2, 0, 373, "300+Sheet1!B3"); - - confirmCell(sheet2, 11, 0, 300, "300+Sheet1!#REF!"); - - - // Note - named ranges formulas have not been updated - } - - private static void confirmRow(Sheet sheet, int rowIx, double valA, double valB, double valC, - String formulaA, String formulaB, String formulaC) { - confirmCell(sheet, rowIx, 4, valA, formulaA); - confirmCell(sheet, rowIx, 5, valB, formulaB); - confirmCell(sheet, rowIx, 6, valC, formulaC); - } - - private static void confirmCell(Sheet sheet, int rowIx, int colIx, - double expectedValue, String expectedFormula) { - Cell cell = sheet.getRow(rowIx).getCell(colIx); - assertEquals(expectedValue, cell.getNumericCellValue(), 0.0); - assertEquals(expectedFormula, cell.getCellFormula()); - } -} diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java b/src/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java index d29469111d..962a565503 100755 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java @@ -19,6 +19,7 @@ package org.apache.poi.hssf.usermodel; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.usermodel.BaseTestSheetShiftRows; /** * Tests row shifting capabilities. @@ -31,7 +32,7 @@ public final class TestSheetShiftRows extends BaseTestSheetShiftRows { @Override protected Workbook openSampleWorkbook(String sampleFileName) { - return HSSFTestDataSamples.openSampleWorkbook(sampleFileName + ".xls"); + return HSSFTestDataSamples.openSampleWorkbook(sampleFileName); } @Override @@ -46,4 +47,29 @@ public final class TestSheetShiftRows extends BaseTestSheetShiftRows { protected Workbook createWorkbook() { return new HSSFWorkbook(); } + + public void testShiftRows() { + baseTestShiftRows("SimpleMultiCell.xls"); + } + + public void testShiftRow() { + baseTestShiftRow(); + } + + public void testShiftRow0() { + baseTestShiftRow0(); + } + + public void testShiftRowBreaks() { + baseTestShiftRowBreaks(); + } + + public void testShiftWithComments() { + baseTestShiftWithComments("comments.xls"); + } + + public void testShiftWithFormulas() { + baseTestShiftWithFormulas("ForShifting.xls"); + } + } diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java new file mode 100755 index 0000000000..7b83cbbd53 --- /dev/null +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java @@ -0,0 +1,276 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.ss.usermodel; + +import junit.framework.TestCase; + +/** + * Tests row shifting capabilities. + * + * @author Shawn Laubach (slaubach at apache dot com) + * @author Toshiaki Kamoshida (kamoshida.toshiaki at future dot co dot jp) + */ +public abstract class BaseTestSheetShiftRows extends TestCase { + /** + * Override to provide HSSF / XSSF specific way for re-serialising a workbook + */ + protected abstract Workbook writeOutAndReadBack(Workbook wb); + /** + * Override to provide way of loading HSSF / XSSF sample workbooks + * @param sampleFileName without the ".xls" or ".xlsx" suffix + */ + protected abstract Workbook openSampleWorkbook(String sampleFileName); + /** + * Override to provide way of creating HSSF / XSSF workbooks + */ + protected abstract Workbook createWorkbook(); + + /** + * Tests the shiftRows function. Does three different shifts. + * After each shift, writes the workbook to file and reads back to + * check. This ensures that if some changes code that breaks + * writing or what not, they realize it. + * + * @author Shawn Laubach (slaubach at apache dot org) + */ + public final void baseTestShiftRows(String sampleName){ + // Read initial file in + Workbook wb = openSampleWorkbook(sampleName); + Sheet s = wb.getSheetAt( 0 ); + + // Shift the second row down 1 and write to temp file + s.shiftRows( 1, 1, 1 ); + + wb = writeOutAndReadBack(wb); + + // Read from temp file and check the number of cells in each + // row (in original file each row was unique) + s = wb.getSheetAt( 0 ); + + assertEquals(s.getRow(0).getPhysicalNumberOfCells(), 1); + confirmEmptyRow(s, 1); + assertEquals(s.getRow(2).getPhysicalNumberOfCells(), 2); + assertEquals(s.getRow(3).getPhysicalNumberOfCells(), 4); + assertEquals(s.getRow(4).getPhysicalNumberOfCells(), 5); + + // Shift rows 1-3 down 3 in the current one. This tests when + // 1 row is blank. Write to a another temp file + s.shiftRows( 0, 2, 3 ); + wb = writeOutAndReadBack(wb); + + // Read and ensure things are where they should be + s = wb.getSheetAt(0); + confirmEmptyRow(s, 0); + confirmEmptyRow(s, 1); + confirmEmptyRow(s, 2); + assertEquals(s.getRow(3).getPhysicalNumberOfCells(), 1); + confirmEmptyRow(s, 4); + assertEquals(s.getRow(5).getPhysicalNumberOfCells(), 2); + + // Read the first file again + wb = openSampleWorkbook(sampleName); + s = wb.getSheetAt( 0 ); + + // Shift rows 3 and 4 up and write to temp file + s.shiftRows( 2, 3, -2 ); + wb = writeOutAndReadBack(wb); + s = wb.getSheetAt( 0 ); + assertEquals(s.getRow(0).getPhysicalNumberOfCells(), 3); + assertEquals(s.getRow(1).getPhysicalNumberOfCells(), 4); + confirmEmptyRow(s, 2); + confirmEmptyRow(s, 3); + assertEquals(s.getRow(4).getPhysicalNumberOfCells(), 5); + } + private static void confirmEmptyRow(Sheet s, int rowIx) { + Row row = s.getRow(rowIx); + assertTrue(row == null || row.getPhysicalNumberOfCells() == 0); + } + + /** + * Tests when rows are null. + * + * @author Toshiaki Kamoshida (kamoshida.toshiaki at future dot co dot jp) + */ + public final void baseTestShiftRow() { + Workbook b = createWorkbook(); + Sheet s = b.createSheet(); + s.createRow(0).createCell(0).setCellValue("TEST1"); + s.createRow(3).createCell(0).setCellValue("TEST2"); + s.shiftRows(0,4,1); + } + + /** + * Tests when shifting the first row. + * + * @author Toshiaki Kamoshida (kamoshida.toshiaki at future dot co dot jp) + */ + public final void baseTestShiftRow0() { + Workbook b = createWorkbook(); + Sheet s = b.createSheet(); + s.createRow(0).createCell(0).setCellValue("TEST1"); + s.createRow(3).createCell(0).setCellValue("TEST2"); + s.shiftRows(0,4,1); + } + + /** + * When shifting rows, the page breaks should go with it + * + */ + public final void baseTestShiftRowBreaks() { + Workbook b = createWorkbook(); + Sheet s = b.createSheet(); + Row row = s.createRow(4); + row.createCell(0).setCellValue("test"); + s.setRowBreak(4); + + s.shiftRows(4, 4, 2); + assertTrue("Row number 6 should have a pagebreak", s.isRowBroken(6)); + } + + + public final void baseTestShiftWithComments(String sampleName) { + Workbook wb = openSampleWorkbook(sampleName); + + Sheet sheet = wb.getSheet("Sheet1"); + assertEquals(3, sheet.getLastRowNum()); + + // Verify comments are in the position expected + assertNotNull(sheet.getCellComment(0,0)); + assertNull(sheet.getCellComment(1,0)); + assertNotNull(sheet.getCellComment(2,0)); + assertNotNull(sheet.getCellComment(3,0)); + + String comment1 = sheet.getCellComment(0,0).getString().getString(); + assertEquals(comment1,"comment top row1 (index0)\n"); + String comment3 = sheet.getCellComment(2,0).getString().getString(); + assertEquals(comment3,"comment top row3 (index2)\n"); + String comment4 = sheet.getCellComment(3,0).getString().getString(); + assertEquals(comment4,"comment top row4 (index3)\n"); + + // Shifting all but first line down to test comments shifting + sheet.shiftRows(1, sheet.getLastRowNum(), 1, true, true); + + // Test that comments were shifted as expected + assertEquals(4, sheet.getLastRowNum()); + assertNotNull(sheet.getCellComment(0,0)); + assertNull(sheet.getCellComment(1,0)); + assertNull(sheet.getCellComment(2,0)); + assertNotNull(sheet.getCellComment(3,0)); + assertNotNull(sheet.getCellComment(4,0)); + + String comment1_shifted = sheet.getCellComment(0,0).getString().getString(); + assertEquals(comment1,comment1_shifted); + String comment3_shifted = sheet.getCellComment(3,0).getString().getString(); + assertEquals(comment3,comment3_shifted); + String comment4_shifted = sheet.getCellComment(4,0).getString().getString(); + assertEquals(comment4,comment4_shifted); + + // Write out and read back in again + // Ensure that the changes were persisted + wb = writeOutAndReadBack(wb); + sheet = wb.getSheet("Sheet1"); + assertEquals(4, sheet.getLastRowNum()); + + // Verify comments are in the position expected after the shift + assertNotNull(sheet.getCellComment(0,0)); + assertNull(sheet.getCellComment(1,0)); + assertNull(sheet.getCellComment(2,0)); + assertNotNull(sheet.getCellComment(3,0)); + assertNotNull(sheet.getCellComment(4,0)); + + comment1_shifted = sheet.getCellComment(0,0).getString().getString(); + assertEquals(comment1,comment1_shifted); + comment3_shifted = sheet.getCellComment(3,0).getString().getString(); + assertEquals(comment3,comment3_shifted); + comment4_shifted = sheet.getCellComment(4,0).getString().getString(); + assertEquals(comment4,comment4_shifted); + } + + /** + * See bug #34023 + */ + public void baseTestShiftWithFormulas(String sampleName) { + Workbook wb = openSampleWorkbook(sampleName); + + Sheet sheet = wb.getSheet("Sheet1"); + assertEquals(20, sheet.getLastRowNum()); + + confirmRow(sheet, 0, 1, 171, 1, "ROW(D1)", "100+B1", "COUNT(D1:E1)"); + confirmRow(sheet, 1, 2, 172, 1, "ROW(D2)", "100+B2", "COUNT(D2:E2)"); + confirmRow(sheet, 2, 3, 173, 1, "ROW(D3)", "100+B3", "COUNT(D3:E3)"); + + confirmCell(sheet, 6, 1, 271, "200+B1"); + confirmCell(sheet, 7, 1, 272, "200+B2"); + confirmCell(sheet, 8, 1, 273, "200+B3"); + + confirmCell(sheet, 14, 0, 0.0, "A12"); // the cell referred to by this formula will be replaced + + // ----------- + // Row index 1 -> 11 (row "2" -> row "12") + sheet.shiftRows(1, 1, 10); + + // Now check what sheet looks like after move + + // no changes on row "1" + confirmRow(sheet, 0, 1, 171, 1, "ROW(D1)", "100+B1", "COUNT(D1:E1)"); + + // row "2" is now empty + confirmEmptyRow(sheet, 1); + + // Row "2" moved to row "12", and the formula has been updated. + // note however that the cached formula result (2) has not been updated. (POI differs from Excel here) + confirmRow(sheet, 11, 2, 172, 1, "ROW(D12)", "100+B12", "COUNT(D12:E12)"); + + // no changes on row "3" + confirmRow(sheet, 2, 3, 173, 1, "ROW(D3)", "100+B3", "COUNT(D3:E3)"); + + + confirmCell(sheet, 14, 0, 0.0, "#REF!"); + + + // Formulas on rows that weren't shifted: + confirmCell(sheet, 6, 1, 271, "200+B1"); + confirmCell(sheet, 7, 1, 272, "200+B12"); // this one moved + confirmCell(sheet, 8, 1, 273, "200+B3"); + + // check formulas on other sheets + Sheet sheet2 = wb.getSheet("Sheet2"); + confirmCell(sheet2, 0, 0, 371, "300+Sheet1!B1"); + confirmCell(sheet2, 1, 0, 372, "300+Sheet1!B12"); + confirmCell(sheet2, 2, 0, 373, "300+Sheet1!B3"); + + confirmCell(sheet2, 11, 0, 300, "300+Sheet1!#REF!"); + + + // Note - named ranges formulas have not been updated + } + + private static void confirmRow(Sheet sheet, int rowIx, double valA, double valB, double valC, + String formulaA, String formulaB, String formulaC) { + confirmCell(sheet, rowIx, 4, valA, formulaA); + confirmCell(sheet, rowIx, 5, valB, formulaB); + confirmCell(sheet, rowIx, 6, valC, formulaC); + } + + private static void confirmCell(Sheet sheet, int rowIx, int colIx, + double expectedValue, String expectedFormula) { + Cell cell = sheet.getRow(rowIx).getCell(colIx); + assertEquals(expectedValue, cell.getNumericCellValue(), 0.0); + assertEquals(expectedFormula, cell.getCellFormula()); + } +}