Line 0
Link Here
|
|
|
1 |
package org.apache.poi.ss.formula; |
2 |
|
3 |
import org.apache.poi.ss.usermodel.Cell; |
4 |
import org.apache.poi.ss.usermodel.CellType; |
5 |
import org.apache.poi.ss.usermodel.Sheet; |
6 |
import org.apache.poi.ss.usermodel.Workbook; |
7 |
import org.apache.poi.xssf.usermodel.XSSFRow; |
8 |
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
9 |
import org.junit.Before; |
10 |
import org.junit.Test; |
11 |
|
12 |
import static org.junit.Assert.assertEquals; |
13 |
|
14 |
public class TestCompleteFormulaShifter { |
15 |
private Sheet sheet1; |
16 |
private Workbook wb07; |
17 |
|
18 |
@Before |
19 |
public void init() |
20 |
{ |
21 |
wb07 = new XSSFWorkbook(); |
22 |
sheet1 = wb07.createSheet("sheet1"); |
23 |
XSSFRow row = (XSSFRow)sheet1.createRow(0); |
24 |
row.createCell(0, CellType.NUMERIC).setCellValue(1); |
25 |
row.createCell(1, CellType.NUMERIC).setCellValue(2); |
26 |
row.createCell(2, CellType.FORMULA).setCellFormula("A1+B1"); |
27 |
} |
28 |
|
29 |
@Test |
30 |
public void testFormula(){ |
31 |
String originalFormula = "A1+B1"; |
32 |
|
33 |
CompleteFormulaShifter verticalFormulaShifter = new CompleteFormulaShifter(sheet1, true); |
34 |
verticalFormulaShifter.configureForItemShifting(0, 2, 1); |
35 |
String adjustedFormula = verticalFormulaShifter.getShiftedFormulaForXSSF(originalFormula, 0); |
36 |
assertEquals("A2+B2", adjustedFormula); |
37 |
|
38 |
CompleteFormulaShifter horizontalFormulaShifter = new CompleteFormulaShifter(sheet1, false); |
39 |
horizontalFormulaShifter.configureForItemShifting(0, 2, 1); |
40 |
adjustedFormula = horizontalFormulaShifter.getShiftedFormulaForXSSF(originalFormula, 0); |
41 |
assertEquals("B1+C1", adjustedFormula); |
42 |
} |
43 |
@Test |
44 |
public void testFormulaCell(){ |
45 |
CompleteFormulaShifter horizontalFormulaShifter = new CompleteFormulaShifter(sheet1, false); |
46 |
horizontalFormulaShifter.configureForItemShifting(0, 2, 1); |
47 |
Cell formulaCell = sheet1.getRow(0).getCell(2); |
48 |
//System.out.println(formulaCell.getCellFormula()); |
49 |
horizontalFormulaShifter.shiftFormula(formulaCell); |
50 |
assertEquals("B1+C1", formulaCell.getCellFormula()); |
51 |
} |
52 |
|
53 |
} |