What Happens When Excel Decides to Prettify Your Data For You When You Import it to Ruby on Rails (and More Reasons to Use .CSV Files and Not .XLSX Files)
You've fetched your data from an Excel sheet (.xlsx) using a rake task. You've added models, views, and controllers in Ruby on Rails to ensure that you can get and show your data in your React frontend.
But uh-oh.... your image links aren't working!
![]() |
Awkward Schitts Creek GIF By CBC |
You first take a look at your excel file and the links look just like they should.
Taking a closer look at your image links you discover something odd.
Now back to the heart of the issue. Why did excel screw us over by adding those <html><u> tags? What is a <u> tag anyway? We refresh our memory with a quick google search (as all good developers do).
![]() |
| Google It Jimmy Fallon GIF by The Tonight Show Starring Jimmy Fallon |
Google reminds us that <u></u> tags are used to underline in HTML.
What are we peasants using old school HTML now? Well, we're not! But Microsoft Excel is!
Yes that's right. Under the hood, Excel is adding some <html><u> formatting for us to "pretty print" our links and make them display with a lovely underline for us.
Excel: "Oh, I see this cell contains a url. I will make it look nice for you!" 🤓
Excel then proceeds to add oldschool html markup...
Us: "My those underlines look distinguished and so presentable in this document, thanks Excel!" 😃
Later on...
Us: "I need to export this data to use in my SQL database. I'm going to use the Roo gem to help me with that."
Roo gem: "I see you have information in this cell, I'm not touching that and will import it into SQL exactly as you have formatted it."
Us: "Why is there excess markup baggage on my data?!" 😖
The morale of the story...
Excel is NOT a data medium. It is an analyst tool. Always import a .csv file rather than .xls and you will make your life as a backend developer much easier.
Unfortunately that inline styling really mangled the string we imported. And Roo,


Comments
Post a Comment