Reputation: 159
I am trying to generate excel file and my data is in the form of HTML string. The html string has hyperlinks(anchor tags) in them. the column 1 has a hyperlink and some text after that. however, when viewed in Excel, it makes all the text in that cell as hyperlink. Is it possible to restrict that. Open the below file in browser and it works fine. When opened in excel, it hyperlinks everything in that cell.
<!DOCTYPE html>
<html>
<body>
<table>
<tr>
<td>
<p><a href="https://www.w3schools.com/html/">Visit our HTML tutorial</a>
This is a sample text</p>
</td>
<td>column 2</td>
</tr>
</table>
</body>
</html>
enter code here
Upvotes: 0
Views: 205
Reputation: 166
Are you just opening the .html file directly in Excel? If so, Excel is doing some conversion/interpreting work that we can't exactly see. It will be trial and error if this is the process you're using.
It is likely interpreting that <td>
all as one cell, so it's styling the entire cell with the hyperlink. If you put "This is a sample text"
in its own <td>
so it's in a different cell, that is one way to fix it. You'll have three columns instead of two, but visually it would accomplish what you want.
If you want it in the same cell, I'm not certain if that is possible based on how Excel is interpreting it. I tried all sorts of things (putting the sample text in its own span or p tags, etc) but those placed it in a different row, but it seems like if it goes in the same cell as the link, Excel is going to style the entire cell that way.
If you use a method that gives you more control over the conversion (VBA, etc) then you may have more options.
Upvotes: 0