Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
289 views
in Technique[技术] by (71.8m points)

java - Using Apache POI HSSF, how can I refresh all formula cells at once?

I am filling cells of an Excel file using Apache POI, and there are a lot of formula cells in the document. However, their values are not refreshed when I open the document in Excel.

It's my understanding that I need to use a FormulaEvaluator to refresh formula cells. Is there a way, though, to update all formula cells at once? There are a lot of them, and while making an exhaustive list is not out of question, it's certainly not something I'm very willing to do.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Sure. Refreshing all the formulas in a workbook is possibly the more typical use case anyway.

If you're using HSSF, call evaluatorAllFormulaCells:

 HSSFFormulaEvaluator.evaluateAllFormulaCells(hssfWorkbook)

If you're using XSSF, call evaluatorAllFormulaCells:

 XSSFFormulaEvaluator.evaluateAllFormulaCells(xssfWorkbook)

More details are available on the poi website


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...