ASF Bugzilla – Attachment 35334 Details for
Bug 61516
problem adjusting cell reference in formula to zeroth row
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
minimized version of test case
PoiShifterIssue.java (text/plain), 1.98 KB, created by
Dragan Jovanović
on 2017-09-19 10:16:24 UTC
(
hide
)
Description:
minimized version of test case
Filename:
MIME Type:
Creator:
Dragan Jovanović
Created:
2017-09-19 10:16:24 UTC
Size:
1.98 KB
patch
obsolete
>package inventivio.tactile.msoffice; > >import org.apache.poi.ss.SpreadsheetVersion; >import org.apache.poi.ss.formula.FormulaParser; >import org.apache.poi.ss.formula.FormulaRenderer; >import org.apache.poi.ss.formula.FormulaShifter; >import org.apache.poi.ss.formula.FormulaType; >import org.apache.poi.ss.formula.ptg.Ptg; >import org.apache.poi.ss.usermodel.CellValue; >import org.apache.poi.ss.usermodel.FormulaEvaluator; >import org.apache.poi.xssf.usermodel.*; >import org.junit.Before; >import org.junit.Test; >import static org.junit.Assert.assertEquals; > >public class PoiShifterIssue { > private XSSFWorkbook wb; > private String initialFormula = "A1"; > private final String expectedFormula = "#REF!"; // from ms excel > > @Before > public void init(){ > wb = new XSSFWorkbook(); > XSSFSheet sheet = (XSSFSheet)wb.createSheet("sheet1"); > sheet.createRow(0).createCell(0).setCellValue(1); // A1 = 1 > XSSFCell c3 = sheet.createRow(2).createCell(2); > c3.setCellFormula(initialFormula); // C3 = =A1 > FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); > CellValue cellValue = evaluator.evaluate(c3); > c3.setCellValue(cellValue.getNumberValue()); // evaluate, C3 = 1 > } > > @Test > public void shiftFormulaUp(){ > FormulaShifter formulaShifter = FormulaShifter.createForRowCopy(0, "sheet1", 2/*firstRowToShift*/, 2/*lastRowToShift*/ > , -1/*step*/, SpreadsheetVersion.EXCEL2007); // parameters 2, 2, -1 should mean : move row range [2-2] one level up > XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create((XSSFWorkbook) wb); > Ptg[] ptgs = FormulaParser.parse(initialFormula, fpb, FormulaType.CELL, 0); // [A1] > formulaShifter.adjustFormula(ptgs, 0); // adjusted to [A] > String shiftedFmla = FormulaRenderer.toFormulaString(fpb, ptgs); //A > System.out.println(String.format("initial formula : A1; expected formula value after shifting up : #REF!; actual formula value : %s", shiftedFmla)); > assertEquals(expectedFormula, shiftedFmla); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 61516
:
35324
| 35334 |
35335