Using ImportTableOptions isHtmlString prop is not outputting links correctly

I am inserting rows into a worksheet using the ImportTableOptions() feature. Some of my columns contain html text, and when I set IsHtmlString to true, that text is successfully converted. However, when the text contains an anchor tag, the link is formatted as regular text and is not clickable in the cell. Please see below:

example html string:
"

<a href=“https://reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html”>CN Risk 3 

"

import table options:
var imp = new ImportTableOptions();
imp.InsertRows = true;
imp.IsFieldNameShown = false;
imp.IsHtmlString = true;

output in excel:
image.png (8.7 KB)

@sapplewhite22,

Please notice, I am able to reproduce the issue as you mentioned. I found ImportTableOptions.IsHtmlString property is not inserting hyperlinks correctly. I used the following sample code to import the data into Excel spreadsheet. But in the output file, simple text is added instead of hyperlinked text:
e.g.
Sample code:

            DataTable table = new DataTable();
            table.Columns.Add("ID");
            table.Columns.Add("thelink");
            table.Columns.Add("Start Time");
            string[] addrow = { "1", "<p><a href=\"https://reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html\">CN Risk 3</a>&nbsp;</p>", "1:00 PM" };
            table.Rows.Add(addrow);

            var workbook = new Workbook();
            var ws = workbook.Worksheets[0];
            ws.Cells.ImportData(table, 0, 0, new ImportTableOptions
            {
                IsFieldNameShown = true,
                ConvertNumericData = true,
                NumberFormats = new string[] {null, null, "h:mm AM/PM"},
                IsHtmlString = true


            });
            workbook.Save("e:\\test2\\out1.xlsx");

I have logged a ticket with an id “CELLSNET-50380” for your issue. We will look into it soon.

Once we have an update on it, we will let you know.

1 Like

@sapplewhite22,

This is to inform you that your issue has been resolved. The fix will be included in our upcoming release, Aspose.Cells for .NET 22.3. The next release will be released in the second week of March, 2022. You will also be notified when a new release is published.

1 Like

thank you for the update.

@sapplewhite22,

You are welcome.

The issues you have found earlier (filed as CELLSNET-50380) have been fixed in this update. This message was posted using Bugs notification tool by johnson.shi

Hi,

I updated the aspose package in my project and see that the issue has been resolved. Thank you.
However, if there is text before the anchor tag, the link is still not clickable.

Working:
Link to react”

Link to react text behind

Not working:

text in front

Link to react

text in front Link to react text in back

@sapplewhite22,

How could you do this in MS Excel manually? I tried to accomplish the task manually in MS Excel but to no avail. I add text into a cell and then try to add link to some selected words/chars but could not do that. Could you provide a sample file having your desired hyperlink in tact, we will check it soon.

I have textboxes in my app (1st screenshot) where a user can enter text and copy links inside of it. I am using Aspose Cells for C#, so when I am generating the excel report the html string is produced like it is in the 2nd screenshot.

image.png (1.4 KB)

Aspose example html string.png (4.9 KB)

@sapplewhite22,

Could you please share sample code (runnable) or a standalone console application (source code without compile time errors) and sample file(s) to reproduce the issue on our end. We will check your issue soon.

PS. please zip the files prior attaching here.

Please see attached console application.AsposeExcel.zip (6.0 MB)

@sapplewhite22,

I did test your scenario/case using your sample code. I do not think this is an issue. As I told you, for a cell’s data in MS Excel, you got to specify whole text as hyperlinked text so you cannot add hyperlink to selected/specific words/chars in the text. I tried to achieve your desired task in MS Excel manually using “Hyperlink” option/command but could not do that. Could you please provide a sample Excel file having your desired hyperlinks for selected words/chars in the text for Link3 and Link4. We will check on how to do it via Aspose.Cells APIs.

I understand what you’re saying, and I am not trying to add specific characters or words to a hyperlink.

My scenario is that my application has textboxes on the UI side. So if a user chooses to enter text in the textbox, and then copy and paste a link in the textbox, columns labeled Link3 and Link4 in the sample code will not work.

The forum does not authorize .xlsx extensions, so I have taken a screenshot of the excel file that is generated by the sample code.

I have changed the font color to orange for text that a user may type into a textbox, and changed the font color to green for the link that a user may copy and paste into the textbox.

Examples of how the html strings are generated are in the sample code.

Screenshot 2022-03-24 154848.png (16.7 KB)

@sapplewhite22,

Please zip the Excel file and attach it, we will check it further.

See attached.

AsposeExample.zip (8.5 KB)

@sapplewhite22,

Thanks for the file but we requested you to provide your expected file. I found the Link3 and Link4 cells are not hyperlinked at all (there is no link involved for the selected words/chars in the text), you just applied formatting (set colors and make some words/chars underlined) to those cells. So, kindly provide expected file having selected area/words hyperlinked only for Link3 and Link4. We will check on how to do it via Aspose.Cells APIs.

I cannot do this manually in Excel. If it not possible for links to work under these scenarios I just need confirmation that Aspose cannot generate links this way.

@sapplewhite22,

Aspose.Cells follows MS Excel standards and specifications. I am afraid, if something cannot be done in MS Excel manually, Aspose.Cells cannot do that too.

Okay. I appreciate your help thank you.