rubyXL icon indicating copy to clipboard operation
rubyXL copied to clipboard

Implement support for Excel custom number formats

Open eric-wood opened this issue 11 years ago • 10 comments

I was playing around with this gem (which is great, btw), but it doesn't seem to support number formatting!

The main use-case for this (in my circumstances, at least), would be support for things like decimal truncation. This isn't surprising, I guess, since most people are looking to just get the raw data.

Is there a way to do this? I can provide an example spreadsheet to demonstrate this if necessary!

Thanks :)

eric-wood avatar May 14 '14 04:05 eric-wood

Please provide more details. I will gladly implement anything, as long as I can understand what exactly you want.

weshatheleopard avatar May 14 '14 04:05 weshatheleopard

Okay! The main issue is decimal truncation. See the attached spreadsheet; it displays "0.12" while the value of the cell is a much longer float.

(here's to hoping Github supports file attachments via email?)

On Tue, May 13, 2014 at 11:30 PM, weshatheleopard [email protected]:

Please provide more details. I will gladly implement anything, as long as I can understand what exactly you want.

— Reply to this email directly or view it on GitHubhttps://github.com/weshatheleopard/rubyXL/issues/109#issuecomment-43041122 .

eric-wood avatar May 14 '14 04:05 eric-wood

Here's the spreadsheet in question: https://dl.dropboxusercontent.com/u/7063251/Workbook1.xlsx

Sorry about the temp link, seems like the easiest way to get you the info you need :(

eric-wood avatar May 14 '14 04:05 eric-wood

I downloaded the file, but I will not be able to work on it until tomorrow.

Please provide the following information:

  1. What behavior you observe?
  2. What behavior you expected to observe instead?

weshatheleopard avatar May 14 '14 05:05 weshatheleopard

No rush at all! This is functionality for something that I work on in my spare time...thanks a ton for getting back to me, though!

Steps to reproduce:

  • enter a float with lots of digits (e.g.: 0.123456789)
  • decrease the number of decimal places on the cell to 2 (so the value is now 0.12, using previous example float)

Expected: output should be 0.12 Actual: output is 0.123456789

eric-wood avatar May 14 '14 05:05 eric-wood

"Enter" as in where? Excel or rubyXL? "Output" as in where? Excel or rubyXL?

weshatheleopard avatar May 14 '14 05:05 weshatheleopard

Enter: Excel Output: rubyXL

eric-wood avatar May 14 '14 05:05 eric-wood

I see. Well, at this point this cannot be done. What you effectively asking for is to replicate the Excel's formatting functionality, so it would take Excel's format string and format raw_value according to it. Given that it's a complex language (https://office.microsoft.com/en-us/excel-help/create-a-custom-number-format-HP010342372.aspx), it will take a lot of effort, and at this moment I have other bugs where it would be more beneficial. But, if you are willing to contribute to the project by implementing such formatter, feel free to do so!

weshatheleopard avatar May 14 '14 05:05 weshatheleopard

Thanks for looking into it, I was worried this might be the case. I'll look into implementing this in the future!

eric-wood avatar May 14 '14 05:05 eric-wood