Aspose.Cells harms XLS files when we try to add long hyperlinks

We noticed that Aspose.Cells is harming XLS files when we try to update hyperlinks with some values that are longer than 255 characters.

This is true for every type of hyperlink that we tried

  • Regular hyperlinks (worksheet.Hyperlinks, sample project attached)
  • Shapes (Hyperlink.Address property in worksheet.Shapes)
  • Pictures (SourceFullName property in worksheet.Pictures)
  • Pivot Tables (DataSource property in worksheet.PivotTables)
  • External Links (OriginalDataSource/DataSource properties in worksheet.ExternalLinks)
  • Ole Objects (ImageSourceFullName property in worksheet.OleObjects)
  • Formulas (Formula property in worksheet.Cell object that starts with “HYPERLINK(”)
  • CustomXmlParts/DataConnections

To make it simple, we’ve created a sample file with only regular hyperlinks, but the issue happens with any of those objects.
We understand that for some of those XLS files themselves can have the limit of 255 characters and we can’t do much about it. However, for regular hyperlinks we are able to manually update the file with a long hyperlink and it saves and works correctly (for shapes, pictures too).

We would like to understand if there is some issue in the way Aspose is updating the hyperlink property.

Sample project - AsposeXlsCellsFileHarm.zip
Sample file - Sample XLS File.xls
Link we are trying to update to - X:\TEST SERVICE\Senior Manager’s Folder\TT\Statements Company\Event Id 12547- Senior Fund 2024\Test Mechanism - Changed Link Statement Test Output\Attachments\AnotherTestNumber\VeryTestLocation\VeryTestFolder\VeryLongPathMoreThanTwoHundredFiftyFiveCharacters.pdf

Code

static void Main(string[] args)
{
    // Replace the name with the actual filename you are using.
    string filePath = @"Sample File\Sample File.xls";
    string modifiedFilePath = @"Sample File\Sample File - Aspose Modified.xls";

    try
    {
        using (MemoryStream asposeStream = new MemoryStream())
        {
            using (var stream = File.OpenRead(filePath))
            {
                stream.CopyTo(asposeStream);
            }

            asposeStream.Position = 0;

            var loadOptions = new LoadOptions
            {
                MemorySetting = MemorySetting.MemoryPreference
            };

            var workbook = new Workbook(asposeStream, loadOptions);
            Console.WriteLine($"Successfully loaded {filePath}");

            foreach (var worksheet in workbook.Worksheets)
            {
                try
                {
                    ProcessHyperlinks(worksheet);
                }
                catch (Exception ex)
                {
                    throw new Exception($@"Error processing worksheet '{worksheet.Name}': {ex.Message}", ex);
                }
            }

            workbook.Save(modifiedFilePath, SaveFormat.Excel97To2003);
            Console.WriteLine($"Successfully saved back to {modifiedFilePath}");
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine($"Exception with {filePath}. Message = {ex.Message}");
    }
    Console.ReadKey();
}

private static void ProcessHyperlinks(Worksheet worksheet)
{
    foreach (var hyperlink in worksheet.Hyperlinks)
    {
        // Update hyperlinks with a long link (>255 characters).
        string longLinkPath =
            @"X:\\TEST SERVICE\\Senior Manager's Folder\\TT\\Statements Company\\Event Id 12547- Senior Fund 2024\\Test Mechanism - Changed Link Statement Test Output\\Attachments\\AnotherTestNumber\\VeryTestLocation\\VeryTestFolder\\VeryLongPathMoreThanTwoHundredFiftyFiveCharacters.pdf";

        hyperlink.Address = longLinkPath;
    }
}

@vahem,

I reproduced the issue as you mentioned by using your template Excel file with sample code snippet. I found Aspose.Cells corrupts XLS file when we try to add long hyperlinks.

We require thorough evaluation of your issue. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-55839

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@vahem
This is a limitation of XLS.

  1. We can only remove characters exceeding 255 of regular hyperlink to prevent the file from crashing again.
  2. For Formulas (Formula property in worksheet.Cell object that starts with "HYPERLINK(‘’), the max length of parameter in Function is 255. So an exception will be thrown.

@simon.zhao Thanks for the response. We understand about the limitation of XLS formulas. However, regular links/pictures/shapes seem to not have this limitation when we manually add the hyperlink mentioned above.

Please see the sample file attached (the link is added manually)

https://files.axiomint.com/external/file/l7haw5b812f9c43ba42078f61d368c87375d4

@simon.zhao Thanks for the response. We understand about the limitation of XLS formulas. However, regular links/pictures/shapes and some other objects does not seem to have this limitation when we manually add the hyperlink mentioned above.

Please see the sample file attached

https://files.axiomint.com/file/l7haw5b812f9c43ba42078f61d368c87375d4

@vahem,

Thanks for sharing new file and further findings/details.

We have logged it with your existing ticket “CELLSNET-55839” into our database. We will evaluate and look into it soon.

1 Like

@vahem
Thanks for your template xls file, we have found how to support long regular hyperlinks of xls file. We will fix it soon.

@simon.zhao Thanks a lot. As I mentioned earlier, the same issue was happening when we were updating Hyperlink/DataSource properties of some other Excel objects as well.

In case of Formulas, I think Aspose.Cells successfully does not allow this change and throws the exception (because of the 255 character limit).

However, shapes/pictures and some other objects we think allow long hyperlinks when added manually similarly to regular hyperlinks. Any chance those can be fixed along with the regular hyperlinks?

@vahem,

Thanks for sharing further details.

Sure, we will also consider to incorporate the fix for hyperlinks for other Excel objects. Hopefully the fix will be included in our upcoming release (Aspose.Cells v24.6) that is due in the second week of June next month.

@vahem
Please check the attached file which contains long hyperlinks of regular and shape.
CellsNet55839.zip (6.1 KB)

@simon.zhao Thanks for the sample file. The regular hyperlink and the shape in this sample file work good.

@vahem
You are welcome !
We will include the fix in the version 24.6.

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

Unfortunately, we are still able to reproduce the issue using Aspose.Cells 24.6 version using the sample file and sample project we’ve already provided.
We haven’t tested all types of links mentioned in the ticket description. The issue can already be reproduced with a simple regular hyperlink.

@vahem,

I tested your scenario using your two files, “Sample File.xls” and “Sample File with long character link.xls,” with your original project using Aspose.Cells v24.6. It works fine, and I did not encounter any issues with the output files generated. Please find attached the two output XLSX files in the zipped archive for your reference.
files1.zip (12.0 KB)

Please ensure that you are using the latest version of Aspose.Cells for .NET. You may print the version number in the code for confirmation if you are using the correct version or not. Add the following line of code at the start of your program:

Console.WriteLine(Aspose.Cells.CellsHelper.GetVersion());

@amjad.sahi We get corruption dialog with both files that you attached when we try to open it with Microsoft Excel. Please see the screenshot showing the issue

Screenshot 2024-07-08 190636.png (94.8 KB)

We tested this with both Office 365 (version 2406) and Office 2021 (version 2108).

@vahem,

Thanks for the screenshot.

I used MS Excel 2010 and MS Excel 2019 and both worked fine when I opened the output files manually. Could you try using MS Excel 2019/2010 if you still get a corruption dialog when opening the files?

@amjad.sahi Unfortunately, we can’t find people in the company who are still using those versions of Excel. Any chance that you can test it on the latest version of Excel on your end?

@vahem
I have got same corrupted dialog in office 365. We will look into this issue again.
Sorry for the inconvenience!

1 Like

@vahem,

Your issue (logged earlier as “CELLSNET-55839”) has been resolved precisely now. The fix/enhancement will be included in the next release (Aspose.Cells v24.7) scheduled for release this week. We will let you know when the next version is released.

1 Like