roo-rb / roo

Roo provides an interface to spreadsheets of several sorts.
MIT License
2.79k stars 502 forks source link

Support formatting excel currencies #557

Closed bmidgley closed 2 years ago

bmidgley commented 3 years ago

Summary

Can formatted currencies include the currency symbol? This PR adds Roo support for calling format on a currency-formatted cell and getting a value with the currency symbol back.

Other Information

There is a simple format for US currencies and a more complex form for others. Anything that's not a US currency appears to shift the format entirely from "Currency" to "Accounting".

The accounting format appears to be multiple functions which probably need a new library to fully execute. What I do instead is look for a pattern in the first function that appears to identify the currency symbol and digital formatting.

The sample I got for applying Euro formatting is:

([$€-2]\ * #,##0.00);([$€-2]\ * (#,##0.00);([$€-2]\ * "-"??);(@_)

And I just used the first part and extracted the currency symbol and format there.

bmidgley commented 3 years ago

@simonoff is this something you can review for merge? We are using it in prod and it's working out fine.