简体   繁体   中英

Apache POI HSSF/XSSF - Evaluating Formulas That Don't Live In Cells

With a known formula extracted from a spreadsheet, is it possible to apply/evaluate the formula without having it reside in an actual cell?

I suppose one can create / locate a blank cell on the sheet (anyone have any ideas how this might be done efficiently?) and evaluate the formula this way, but is there a better way?

I'm not sure that POI is the way to do for this, given that it looks after creating/reading/writing spreadsheets. Have you looked at invoking the Excel COM object (via, say, JACOB ), and running the formulas in Excel itself ?

Excel does let you evaluate a formula without it having to reside in a cell. You can do it via the old XLM macro language with EVALUATE or through the C API, and via VBA with Application.Evaluate or Worksheet.Evaluate .

Of course, that information might be of no help if all you have is the extracted formula and not access to Excel. If you know the formulas will be simple enough, I can see evaluating them yourself or with another tool (although I don't know of anything specific). In general, though, you will need not only access to Excel, but also the actual document the formulas are in, since a formula can call user-written VBA/XLL functions, use defined names, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM