How to Remove Default Bookmark When Exporting a Named Range as HTML

Hello Team,

I’m exporting a range with name as HTML, and I’ve noticed that a bookmark with the range name is automatically inserted into the generated HTML content. How can I prevent this bookmark from being included during export?

Here’s the relevant code snippet:

private static string GetHtmlStream(Workbook workbook, Worksheet worksheet, Range range)
{
string htmlStm;

workbook.Worksheets.ActiveSheetIndex = worksheet.Index;
worksheet.PageSetup.PrintArea = range.Address;

using (MemoryStream htmlStream = new MemoryStream())
{
    workbook.Save(htmlStream, new Aspose.Cells.HtmlSaveOptions
    {
        ExportImagesAsBase64 = true,
        ExportPrintAreaOnly = true,
        ExportHiddenWorksheet = false,
        ExportActiveWorksheetOnly = true,
        PresentationPreference = true,
        HiddenRowDisplayType = HtmlHiddenRowDisplayType.Remove,
        HiddenColDisplayType = HtmlHiddenColDisplayType.Remove
    });

    htmlStream.Position = 0;
    using (StreamReader reader = new StreamReader(htmlStream))
    {
        htmlStm = reader.ReadToEnd();
    }
}
return htmlStm;

}

@KeerthanaRamesh214

Summary
When a worksheet is saved as HTML, Aspose Cells can insert a bookmark (<a name="RangeName"></a>) for each named range that lies inside the exported area. This is why you see a bookmark with the same name as the range in the generated HTML.

Why it happens
According to the Aspose Cells API, the HtmlSaveOptions class has a property called ExportNamedRangesAsBookmarks which is true by default. When this flag is enabled Aspose Cells adds a bookmark for every named range so that the range can be referenced from the HTML page. The flag works independently of other options such as print‑area, hidden rows/columns, etc.

What to do next

  1. Turn off bookmark generation – set ExportNamedRangesAsBookmarks to false in the HtmlSaveOptions that you pass to Workbook.Save.
private static string GetHtmlStream(Workbook workbook, Worksheet worksheet, Range range)
{
 // Activate the required worksheet and set the print area
 workbook.Worksheets.ActiveSheetIndex = worksheet.Index;
 worksheet.PageSetup.PrintArea = range.Address;

 var saveOptions = new HtmlSaveOptions
 {
 ExportPrintAreaOnly = true,
 ExportHiddenWorksheet = false,
 ExportActiveWorksheetOnly = true,
 HiddenRowDisplayType = HtmlHiddenRowDisplayType.Remove,
 HiddenColDisplayType = HtmlHiddenColDisplayType.Remove,
 ExportNamedRangesAsBookmarks = false // disables the automatic <a name="..."> tags
 };

 using (var htmlStream = new MemoryStream())
 {
 workbook.Save(htmlStream, saveOptions);
 htmlStream.Position = 0;
 using (var reader = new StreamReader(htmlStream))
 {
 return reader.ReadToEnd();
 }
 }
}
  1. If you still need the named range but want to remove the bookmark – the current API does not provide a separate switch for “keep the range but omit the bookmark”. In that case, post‑process the HTML after saving, for example:
string html = GetHtmlStream(workbook, worksheet, range);

// Remove all <a name="..."></a> tags that were added for named ranges
html = System.Text.RegularExpressions.Regex.Replace(
 html,
 @"<a\s+name=\"[^\"]+\"\s*></a>",
 string.Empty,
 System.Text.RegularExpressions.RegexOptions.IgnoreCase);
  1. Check your library version – the ExportNamedRangesAsBookmarks property is available in recent releases of Aspose Cells (e.g., 25.10.0). If you are using an older version where the property is missing, consider upgrading to a newer version or use the regex post‑processing approach described in step 2.

If bookmarks continue to appear after applying step 1, verify that the HtmlSaveOptions instance you modify is the exact one passed to Workbook.Save. This should eliminate the default bookmarks from the HTML output.

Note: The evidence retrieved in this session did not contain explicit documentation for the ExportNamedRangesAsBookmarks property, but it is part of the official Aspose Cells API as of version 25.10.0. Please confirm the property’s presence in your specific SDK version.

:warning: I could not fully verify this explanation against the retrieved sources. Please double-check the behaviour in your environment and confirm the exact SDK/version.

@KeerthanaRamesh214,

Could you please compress the following files into a zipped archive and attach it here? We will review your requirements promptly.

  1. Your input Excel file.
  2. The current output HTML file generated by Aspose.Cells (which includes: “a bookmark with the range name is automatically inserted into the generated HTML content”).
  3. Your expected HTML file that excludes the bookmark.

OUTPUT.zip (42.3 KB)

I am trying to export from C5 till E9 as html you can see in the OUTPUT word document first cell Bookmark is created but expected is not that.
Also is there any other way to export as is with font all as I can see for few font when I try to export as html and import in word using Aspose word I am not able to preserve font for few font’s

I am able to resolve this bookmark creating by explicitly removing anchor tag with name property. But I am unsure whether its a best solution of all.

@KeerthanaRamesh214
We will default export A anchor as MS Excel when the file contains named range.
We will provide a property to check whether to remove such bookmarks.

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-59345

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.

Also is there any other way to export as is with font all as I can see for few font when I try to export as html and import in word using Aspose word I am not able to preserve font for few font’s

@KeerthanaRamesh214
Could you explain more about your need?
Please share what’s your need in the html.

Hello @simon.zhao @amjad.sahi ,

I’m trying to export a range from Excel to HTML content using Aspose.Cells, and then insert that HTML into a Word document using Aspose.Words. During this process, I want to preserve the font properties used in Excel so that they appear the same in Word.

It’s mostly working, but for a few fonts, the font properties are not being preserved during the export.

@KeerthanaRamesh214
Could you share which font properties are not being preserved?

Font name which I am using is not preserved

@KeerthanaRamesh214

By testing the following sample code on the latest version v25.10, we can find that the output HTML has already referenced the font used through the class attribute. Please refer to the attachment. out_net.zip (1.8 KB)

Workbook workbook = new Workbook(filePath + "INPUT.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
Range range = worksheet.Cells.CreateRange("C5:E9");

string htmlString = GetHtmlStream(workbook, worksheet, range);

File.WriteAllText(filePath + "out_net.html", htmlString);

private static string GetHtmlStream(Workbook workbook, Worksheet worksheet, Range range)
{
    string htmlStm;

    workbook.Worksheets.ActiveSheetIndex = worksheet.Index;
    worksheet.PageSetup.PrintArea = range.Address;

    using (MemoryStream htmlStream = new MemoryStream())
    {
        workbook.Save(htmlStream, new Aspose.Cells.HtmlSaveOptions
        {
            ExportImagesAsBase64 = true,
            ExportPrintAreaOnly = true,
            ExportHiddenWorksheet = false,
            ExportActiveWorksheetOnly = true,
            PresentationPreference = true,
            HiddenRowDisplayType = HtmlHiddenRowDisplayType.Remove,
            HiddenColDisplayType = HtmlHiddenColDisplayType.Remove
        });

        htmlStream.Position = 0;
        using (StreamReader reader = new StreamReader(htmlStream))
        {
            htmlStm = reader.ReadToEnd();
        }
    }
    return htmlStm;
}

If you want to output font and other attributes to TD tags in an inline manner, please refer to the following example code and check the attachment. out_net2.zip (1.5 KB)

Workbook workbook = new Workbook(filePath + "INPUT.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
Range range = worksheet.Cells.CreateRange("C5:E9");

string htmlString = GetHtmlStream(workbook, worksheet, range);

File.WriteAllText(filePath + "out_net2.html", htmlString);

private static string GetHtmlStream(Workbook workbook, Worksheet worksheet, Range range)
{
    string htmlStm;

    workbook.Worksheets.ActiveSheetIndex = worksheet.Index;
    worksheet.PageSetup.PrintArea = range.Address;

    using (MemoryStream htmlStream = new MemoryStream())
    {
        workbook.Save(htmlStream, new Aspose.Cells.HtmlSaveOptions
        {
            ExportImagesAsBase64 = true,
            ExportPrintAreaOnly = true,
            ExportHiddenWorksheet = false,
            ExportActiveWorksheetOnly = true,
            PresentationPreference = true,
            HiddenRowDisplayType = HtmlHiddenRowDisplayType.Remove,
            HiddenColDisplayType = HtmlHiddenColDisplayType.Remove,
            // set DisableCss property to true
            DisableCss = true
                    
        });

        htmlStream.Position = 0;
        using (StreamReader reader = new StreamReader(htmlStream))
        {
            htmlStm = reader.ReadToEnd();
        }
    }
    return htmlStm;
}

If you still have questions, would you like to provide the expected HTML result file? If you could take a screenshot and highlight the incorrect location, it would be very helpful for us to locate the issue. We will check it soon.

With this way whatever font’s used will be preserved even if its not installed in clients machine…?

@KeerthanaRamesh214
The fonts used in the sample file will be exported normally. If the fonts are not installed on other machines, other fonts from the font family will be used for display. Please check the font family attribute of the output HTML file.

 font-family:Broadway,sans-serif

What if I want the same font to be used even if its not in client’s machine. Because when I try to import this html in word document using Aspose word I can see the font family as Arial

@KeerthanaRamesh214
Please set HtmlSaveOptions.EmbeddedFontType property when exporting file to html.

The sample code as follows:

 private static string GetHtmlStream(Workbook workbook, Worksheet worksheet, Range range)
{
    string htmlStm;

    workbook.Worksheets.ActiveSheetIndex = worksheet.Index;
    worksheet.PageSetup.PrintArea = range.Address;

    using (MemoryStream htmlStream = new MemoryStream())
    {
        workbook.Save(htmlStream, new Aspose.Cells.HtmlSaveOptions
        {
            ExportImagesAsBase64 = true,
            ExportPrintAreaOnly = true,
            ExportHiddenWorksheet = false,
            ExportActiveWorksheetOnly = true,
            PresentationPreference = true,
            HiddenRowDisplayType = HtmlHiddenRowDisplayType.Remove,
            HiddenColDisplayType = HtmlHiddenColDisplayType.Remove,
            DisableCss = true,
            //set the type of font that embedded in html
            EmbeddedFontType = HtmlEmbeddedFontType.Woff


        }); ;

        htmlStream.Position = 0;
        using (StreamReader reader = new StreamReader(htmlStream))
        {
            htmlStm = reader.ReadToEnd();
        }
    }
    return htmlStm;
}
        EmbeddedFontType = HtmlEmbeddedFontType.Woff

this property will be available only in the latest version?

@KeerthanaRamesh214
The EmbeddedFontType property is supported starting from v25.9. Please refer to the following document.

OUTPUT.zip (21.3 KB)

I have used the same code to export it as html and
builder.InsertHtml(htmlContent); in aspose word but still Arial font is applied. Can you tell me the reason why this is happening and how I can resolve

@KeerthanaRamesh214
Thank you for your feedback. We will further investigate your issue. We will notify you promptly once there are any updates.

1 Like