Hello,
I need a function to change the HyperlinkBase like this:
workbook.Settings.HyperlinkBase = “.”;
Instead of changing it manuylly:
Open the Excel document for which you want to set a hyperlink base.
On the File menu, click Informations, and then click Show more properties.
In the Linkbase box, type .
Reason:
If Excel links with a relative path exist, these are automatically overwritten when the file is copied to another location. According to the AI, this is prevented if a dot is set in the HyperlinkBasis field.
To change the HyperlinkBase in an Excel workbook programmatically, you can use the Aspose.Cells library. The HyperlinkBase property is essential for ensuring that relative paths in hyperlinks are correctly interpreted when the file is moved to a different location.
Solution
You can set the HyperlinkBase property directly on the workbook’s settings. Here’s how you can do it:
Code
Here’s a simple code snippet to change the HyperlinkBase to a dot (.):
// Load the workbook
Workbook workbook = new Workbook("path/to/your/file.xlsx");
// Set the HyperlinkBase
workbook.Settings.HyperlinkBase = ".";
// Save the workbook
workbook.Save("path/to/your/modified_file.xlsx");
This code loads an existing Excel file, sets the HyperlinkBase to the current directory, and then saves the modified file.
Next Steps
Replace "path/to/your/file.xlsx" with the actual path to your Excel file.
Run the code to apply the changes.
Verify that the hyperlinks in the Excel file are now using the specified HyperlinkBase.
If you have any questions or need further assistance, please feel free to ask!
Aspose.Cells supports to manipulate the document properties (built-in and custom). Could you please try setting the HyperlinkBase property under BuiltInDocumentProperties if it works for your needs,
e.g.,
@BeniL
Thank you for your feedback. You are welcome. I’m glad you solved the issue with the suggested code. If you have any questions, please feel free to contact us at any time.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.