docx4j
docx4j copied to clipboard
Insert numeric variable to xlsx
I'd like to insert to xlsx a value that is of type BigDecimal.When I change it to string and call the variableReplace
method, the value is pasted as a text. I cannot run any formulas against it. How can I replace a variable in a spreadsheet so its value is treated as a number?
Interesting question. It needs to be a string to contain a variable, but the simple variable replacement code can't convert it to a number.
Thinking out loud, one approach would be to know ahead of time which of your cells contained "numeric variables". For example you could use the convention ${keyname_numbertype}. Before doing the replacement, some code could execute to make a list of all the cells containing numeric variables. Then do the replacement. Then run the code to switch the cell type of each cell in the list.
But I suspect you'd still have a problem setting up your formulas in Excel, which would want numbers in the first place, not variables. If so, I guess you'd need to start with numbers in your xlsx (for example, in say cell C3). Then you might be better off dropping the xlsx4j variable replacement, and simply programmatically replacing the value at C3 with what you want.