}
}
@Test
public void testInsertColumnC() {
Worksheet sheet1 = _workbook.getWorksheet("Sheet1");
Row row1 = sheet1.getRow(0);
Row row2 = sheet1.getRow(1);
Row row3 = sheet1.getRow(2);
Row row4 = sheet1.getRow(3);
Row row5 = sheet1.getRow(4);
Row row6 = sheet1.getRow(5);
assertEquals(1, row1.getCell(5).getNumericCellValue(), 0.0000000000000001); //F1: 1
assertEquals(2, row2.getCell(5).getNumericCellValue(), 0.0000000000000001); //F2: 2
assertEquals(3, row3.getCell(5).getNumericCellValue(), 0.0000000000000001); //F3: 3
assertEquals(7, row4.getCell(0).getNumericCellValue(), 0.0000000000000001); //A4: 7
assertEquals(9, row1.getCell(2).getNumericCellValue(), 0.0000000000000001); //C1: 9
assertEquals(11, row1.getCell(3).getNumericCellValue(), 0.0000000000000001); //D1: 11
byte[] REDColor = new byte[] {(byte)0xff, 0, 0};
byte[] YELLOWColor = new byte[] {(byte)0xff, (byte)0xff, 0};
byte[] ffg = ((XSSFColor)row1.getCell(1).getCellStyle().getFillForegroundColorColor()).getRgb();
assertColors(REDColor, ffg);
byte[] fbg = ((XSSFColor)row1.getCell(1).getCellStyle().getFillBackgroundColorColor()).getRgb();
assertColors(YELLOWColor, fbg);
//A1: =SUM(F1:F3)
Cell cellA1 = row1.getCell(0); //A1: =SUM(F1:F3)
CellValue valueA1 = _evaluator.evaluate(cellA1);
assertEquals(6, valueA1.getNumberValue(), 0.0000000000000001);
assertEquals(Cell.CELL_TYPE_NUMERIC, valueA1.getCellType());
testToFormulaString(cellA1, "SUM(F1:F3)");
//A2: =SUM(D2:XFD2) XFD: 16384
Cell cellA2 = row2.getCell(0);
CellValue valueA2 = _evaluator.evaluate(cellA2);
assertEquals(2, valueA2.getNumberValue(), 0.0000000000000001);
assertEquals(Cell.CELL_TYPE_NUMERIC, valueA2.getCellType());
testToFormulaString(cellA2, "SUM(D2:XFD2)");
//A3: =SUM(XFC3:XFD3) XFC: 16383, XFD: 16384
Cell cellA3 = row3.getCell(0);
CellValue valueA3 = _evaluator.evaluate(cellA3);
assertEquals(0, valueA3.getNumberValue(), 0.0000000000000001);
assertEquals(Cell.CELL_TYPE_NUMERIC, valueA3.getCellType());
testToFormulaString(cellA3, "SUM(XFC3:XFD3)");
//A5: =SUM(C1:D1)
Cell cellA5 = row5.getCell(0);
CellValue valueA5 = _evaluator.evaluate(cellA5);
assertEquals(20, valueA5.getNumberValue(), 0.0000000000000001);
assertEquals(Cell.CELL_TYPE_NUMERIC, valueA5.getCellType());
testToFormulaString(cellA5, "SUM(C1:D1)");
//A6: =SUM(B1:D1)
Cell cellA6 = row6.getCell(0);
CellValue valueA6 = _evaluator.evaluate(cellA6);
assertEquals(20, valueA6.getNumberValue(), 0.0000000000000001);
assertEquals(Cell.CELL_TYPE_NUMERIC, valueA6.getCellType());
testToFormulaString(cellA6, "SUM(B1:D1)");
//H1: =SUM(F1:F3)
Cell cellH1 = row1.getCell(7);
CellValue valueH1 = _evaluator.evaluate(cellH1);
assertEquals(6, valueH1.getNumberValue(), 0.0000000000000001);
assertEquals(Cell.CELL_TYPE_NUMERIC, valueH1.getCellType());
testToFormulaString(cellH1, "SUM(F1:F3)");
//H4: =A4
Cell cellH4 = row4.getCell(7);
CellValue valueH4 = _evaluator.evaluate(cellH4);
assertEquals(7, valueH4.getNumberValue(), 0.0000000000000001);
assertEquals(Cell.CELL_TYPE_NUMERIC, valueH4.getCellType());
testToFormulaString(cellH4, "A4");
//Insert before column C
BookHelper.insertColumns(sheet1, 2, 1, Range.FORMAT_LEFTABOVE);
_evaluator.notifySetFormula(cellA1);
_evaluator.notifySetFormula(cellA2);
_evaluator.notifySetFormula(cellA3);
_evaluator.notifySetFormula(cellA5);
_evaluator.notifySetFormula(cellA6);
assertEquals(sheet1.getColumnWidth(1), sheet1.getColumnWidth(2)); //column c width == column b width
assertColors(REDColor, ((XSSFColor)row1.getCell(1).getCellStyle().getFillForegroundColorColor()).getRgb());
assertColors(YELLOWColor, ((XSSFColor)row1.getCell(1).getCellStyle().getFillBackgroundColorColor()).getRgb());
assertColors(REDColor, ((XSSFColor)row1.getCell(2).getCellStyle().getFillForegroundColorColor()).getRgb());
assertColors(YELLOWColor, ((XSSFColor)row1.getCell(2).getCellStyle().getFillBackgroundColorColor()).getRgb());
assertEquals(1, row1.getCell(6).getNumericCellValue(), 0.0000000000000001); //G1: 1
assertEquals(2, row2.getCell(6).getNumericCellValue(), 0.0000000000000001); //G2: 2
assertEquals(3, row3.getCell(6).getNumericCellValue(), 0.0000000000000001); //G3: 3
assertEquals(7, row4.getCell(0).getNumericCellValue(), 0.0000000000000001); //A4: 7
//A1: =SUM(G1:G3)
valueA1 = _evaluator.evaluate(cellA1);
assertEquals(6, valueA1.getNumberValue(), 0.0000000000000001);
assertEquals(Cell.CELL_TYPE_NUMERIC, valueA1.getCellType());
testToFormulaString(cellA1, "SUM(G1:G3)");
//A2: =SUM(E2:XFD2) XFD: 16384
valueA2 = _evaluator.evaluate(cellA2);
assertEquals(2, valueA2.getNumberValue(), 0.0000000000000001);
assertEquals(Cell.CELL_TYPE_NUMERIC, valueA2.getCellType());
testToFormulaString(cellA2, "SUM(E2:XFD2)");
//A3: =SUM(XFD3:XFD3) XFD: 16384
cellA3 = row3.getCell(0); //A3: =SUM(IU3:IV3)
valueA6 = _evaluator.evaluate(cellA3);
assertEquals(0, valueA6.getNumberValue(), 0.0000000000000001);
assertEquals(Cell.CELL_TYPE_NUMERIC, valueA6.getCellType());
testToFormulaString(cellA3, "SUM(XFD3:XFD3)");
//A5: =SUM(C1:D1) -> =SUM(D1:E1)
cellA5 = row5.getCell(0);
valueA5 = _evaluator.evaluate(cellA5);
assertEquals(20, valueA5.getNumberValue(), 0.0000000000000001);
assertEquals(Cell.CELL_TYPE_NUMERIC, valueA5.getCellType());
testToFormulaString(cellA5, "SUM(D1:E1)");
//A6: =SUM(B1:D1) -> =SUM(B1:E1)
cellA6 = row6.getCell(0);
valueA6 = _evaluator.evaluate(cellA6);
assertEquals(20, valueA6.getNumberValue(), 0.0000000000000001);
assertEquals(Cell.CELL_TYPE_NUMERIC, valueA6.getCellType());
testToFormulaString(cellA6, "SUM(B1:E1)");