Change HyperlinkBase

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.

@BeniL

Cause

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

  1. Replace "path/to/your/file.xlsx" with the actual path to your Excel file.
  2. Run the code to apply the changes.
  3. 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 .Net doesn’t has the function: workbook.Settings.HyperlinkBase

The AI is halucinating

I found a solution with PowerShell:

$excel = New-Object -ComObject Excel.Application
$workbook = $excel.Workbooks.Open(“C:\DEV\Test.xlsx”)
$workbook.BuiltinDocumentProperties(“Hyperlink base”) = “.”
$workbook.Save()
$workbook.Close()
$excel.Quit()

@BeniL,

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.,

workbook.BuiltInDocumentProperties.HyperlinkBase

Moreover, please see the document on how to manage document properties for your complete reference: Manage Document Properties|Documentation

Let us know if you find any issue.

Hi Amjad,

that’s great, it works.

Thank you very much.

Bernd

@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.