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;
}
}
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.
We can only remove characters exceeding 255 of regular hyperlink to prevent the file from crashing again.
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)
@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.
@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?
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.
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.
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:
@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
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?
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.