I'm working with an Excel list and want to turn:
Quercus agrifolia var. oxyadenia (Torr.) J.T. Howell
into:
<i>Quercus agrifolia</i> var. <i>oxyadenia</i> (Torr.) J.T. Howell
I have the Rich Text formatted list with formatting applied but I want to send it to Access with the formatting tags explicitly included around the related text.
I was looking to do the same thing, and found an answer on MSDN at: Convert contents of a formatted excel cell to HTML format
I hope this helps you as well, it uses an excel macro.
Edit: When using this I needed to modify the code for nested tags, please find my updates to the macro below:
Here's an alternative solution which is faster, but produces messier output (because it uses Word's HTML engine). You need to add the following references to your VBA project:
Then, call the following code by running eg.
convertToHtml(Range("A1:A100"))
in the immediate window:You can clean up the output using regular expressions by adding a reference to Microsoft VBScript Regular Expressions 5.5, and running a function like this:
If you need to convert
<span>
tags to<font>
tags (I also needed to do this because I was importing into an Access rich text field, which doesn't support CSS), try calling this function and passing in the MSHTML objects constructed in theextractFirstParagraph
function:I also considered just saving the whole spreadsheet as HTML from Excel and then using another tool to get that into a format that Access can deal with, but Excel's HTML export generates CSS classes rather than inline styles. This method is also helpful if you only need to convert part of your spreadsheet to HTML.