@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
- 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();
}
}
}
- 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);
- 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.
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.