简体   繁体   中英

Can axlsx convert html format to work in excel?

My DB stores text from a WYSIWYG editor that looks something like this:

<p><s>Hi!</s></p> 
<p>My Name is Bob's.</p> 
<p> </p> 
<p>I like to eat these things:</p> 
<ul> 
 <li>Candy</li> 
 <li>Veggies</li> 
 <li>Everything</li> 
</ul>
<p>Enjoy<sup>2</sup></p>

In my view I have something like:

  sheet.add_row [@event.text], style: font_format

where @event.text is the above html

Is there a way to make this formatting work in excel using axlsx?

I don't think there is any automatic conversion of html to styles. You'd have to write one yourself. I would use the rich text example as a guide.

I believe it handles any normal Axlsx style on a chunk of text. It at least handles bold, italic, and strikethrough.

For a forced line feed use "\\x0A" (breaks between paragraphs.)

But, that means you'll have to parse the html.

Yes, to_spreadsheet is just for you. I have just finish a Rails app using it to generate xlsx file for download. I just follow the instruction and create a view 'show.xlsx.erb' in view directory. And it's done!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM