ongdisheng commented on issue #571:
URL: https://github.com/apache/fesod/issues/571#issuecomment-3538789559
I've tested my proposed approach and below is the result.
## Test code
```java
@Slf4j
public class Issue571Test {
@Test
public void testReadSharedFormulas() {
String fileName = TestFileUtil.getPath() + "temp" + File.separator
+ "issue571" + File.separator +
"shared_formula.xlsx";
List<String> formulas = new ArrayList<>();
FastExcel.read(fileName, DemoData.class, new
AnalysisEventListener<DemoData>() {
@Override
public void invoke(DemoData data, AnalysisContext context) {
log.info("Parsed a data row:{}", JSON.toJSONString(data));
Map<Integer, Cell> cellMap =
context.readRowHolder().getCellMap();
for (Map.Entry<Integer, Cell> entry : cellMap.entrySet()) {
CellData cellData = (CellData) entry.getValue();
if (cellData.getFormulaData() != null) {
String formula =
cellData.getFormulaData().getFormulaValue();
log.info("Cell {} has a formula: {}",
entry.getKey(), formula);
formulas.add(formula);
}
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
log.info("All data analysed. Found {} formulas",
formulas.size());
}
}).sheet().doRead();
}
}
```
## Test result
```bash
PS C:\Users\disheng\Desktop\OSS\fesod\fesod-examples> mvn
"-Dmaven.test.skip=false" test "-Dtest=Issue571Test"
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.apache.fesod.sheet.temp.issue571.Issue571Test
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Parsed a
data row:{}
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Parsed a
data row:{}
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 3 has a
formula: RANDBETWEEN(100,999)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 4 has a
formula: SUM(B2:C2)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 5 has a
formula: SUM($B2:$C2)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 6 has a
formula: SUM($B$2:$C2)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 7 has a
formula: SUM(B2+C2)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Parsed a
data row:{}
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 3 has a
formula: RANDBETWEEN(100,999)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 4 has a
formula: SUM(B3:C3)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 5 has a
formula: SUM($B3:$C3)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 6 has a
formula: SUM($B$2:$C3)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 7 has a
formula: SUM(B3+C3)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Parsed a
data row:{}
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 3 has a
formula: RANDBETWEEN(100,999)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 4 has a
formula: SUM(B4:C4)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 5 has a
formula: SUM($B4:$C4)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 6 has a
formula: SUM($B$2:$C4)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 7 has a
formula: SUM(B4+C4)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Parsed a
data row:{}
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 3 has a
formula: RANDBETWEEN(100,999)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 4 has a
formula: SUM(B5:C5)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 5 has a
formula: SUM($B5:$C5)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 6 has a
formula: SUM($B$2:$C5)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 7 has a
formula: SUM(B5+C5)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Parsed a
data row:{}
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 3 has a
formula: RANDBETWEEN(100,999)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 4 has a
formula: SUM(B6:C6)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 5 has a
formula: SUM($B6:$C6)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 6 has a
formula: SUM($B$2:$C6)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 7 has a
formula: SUM(B6+C6)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Parsed a
data row:{}
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 3 has a
formula: RANDBETWEEN(100,999)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 4 has a
formula: SUM(B7:C7)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 5 has a
formula: SUM($B7:$C7)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 6 has a
formula: SUM($B$2:$C7)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 7 has a
formula: SUM(B7+C7)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Parsed a
data row:{}
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 3 has a
formula: RANDBETWEEN(100,999)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 4 has a
formula: SUM(B8:C8)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 5 has a
formula: SUM($B8:$C8)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 6 has a
formula: SUM($B$2:$C8)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Cell 7 has a
formula: SUM(B8+C8)
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - All data
analysed. Found 35 formulas
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Formulas:
[RANDBETWEEN(100,999), SUM(B2:C2), SUM($B2:$C2), SUM($B$2:$C2), SUM(B2+C2),
RANDBETWEEN(100,999), SUM(B3:C3), SUM($B3:$C3), SUM($B$2:$C3), SUM(B3+C3),
RANDBETWEEN(100,999), SUM(B4:C4), SUM($B4:$C4), SUM($B$2:$C4), SUM(B4+C4),
RANDBETWEEN(100,999), SUM(B5:C5), SUM($B5:$C5), SUM($B$2:$C5), SUM(B5+C5),
RANDBETWEEN(100,999), SUM(B6:C6), SUM($B6:$C6), SUM($B$2:$C6), SUM(B6+C6),
RANDBETWEEN(100,999), SUM(B7:C7), SUM($B7:$C7), SUM($B$2:$C7), SUM(B7+C7),
RANDBETWEEN(100,999), SUM(B8:C8), SUM($B8:$C8), SUM($B$2:$C8), SUM(B8+C8)]
[main] INFO org.apache.fesod.sheet.temp.issue571.Issue571Test - Test
completed. Total formulas found: 35
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.921
s -- in org.apache.fesod.sheet.temp.issue571.Issue571Test
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- jacoco:0.8.14:report (generate-report) @ fesod-examples ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
[INFO]
[INFO] --- jacoco:0.8.14:report-aggregate (generate-aggregate-report) @
fesod-examples ---
[INFO]
------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 5.396 s
[INFO] Finished at: 2025-11-16T13:49:51Z
[INFO]
------------------------------------------------------------------------
```
## Test file
The test file
[shared_formula.xlsx](https://github.com/user-attachments/files/23568492/shared_formula.xlsx)
includes different types of shared formulas:
- `RANDBETWEEN(100,999)`: Function with no cell references
- `SUM(B2:C2)`: Relative references
- `SUM($B2:$C2)`: Column absolute references
- `SUM($B$2:$C2)`: Mixed references
- `SUM(B2+C2)`: Addition formulas
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]