Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Money type #41

Open
Nerian opened this issue Jan 30, 2020 · 5 comments
Open

Money type #41

Nerian opened this issue Jan 30, 2020 · 5 comments

Comments

@Nerian
Copy link

Nerian commented Jan 30, 2020

Hi,

I would like to generate an xlsx file in which one of the columns is a currency type. My objects are Money (https://github.com/RubyMoney/money) instances.

I am currently this:

Money.new(1003450).format(thousands_separator: '', symbol: false, decimal_mark: '.')
=> "10034.50"

The excel is generated with a column of type numeric.

I was wondering if you could add support of currency format.

Thanks.

@felixbuenemann
Copy link
Owner

So what exactly do you expect to happen?

The OpenXML Spreadsheet format has no Type for money, only numbers. The only thing ine could do is apply one of the pre-defined number formats if instances of Money are detected.

I'm also not sure why you are calling Money#format instead of #to_f or #to_d.

@Nerian
Copy link
Author

Nerian commented Feb 2, 2020

"The only thing ine could do is apply one of the pre-defined number formats if instances of Money are detected"

That would be a good quick win 👍

Is it possible to have a number in the cell, like 200.50 and format it like: 200.50 € ?

@Nerian
Copy link
Author

Nerian commented Feb 2, 2020

If you are given an instance of Money, you could extract the symbol, and create the right format for the currency. The cell would have a float, like 200.50, but Excel would present it as 200.50 €. Does this sound possible?

@felixbuenemann
Copy link
Owner

I'd like to avoid coupling xlsxtream to third-party Gems and there are many different ways to format monetary values (leading / trailing symbols, different rounding, thousands separators etc.), so having a one-fits-all format for that doesn't really work.

I've done a spike on adding support for custom formatters, but ran out of time and I'm not yet sure of the performance implications due to the additional indirection, so I'm not sure of I'll add it, since performance is a number one goal of this gem.

In the meantime the easiest workaround would be to store the amount and currency of the money instance in different columns of the worksheet, which also makes it much easier to work with in Excel.

@Nerian
Copy link
Author

Nerian commented Feb 10, 2020

Makes sense. Performance is top priority for me too and the reason why I picked this gem. Thanks for your work 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants