[]
        
(Showing Draft Content)

HtmlSaveOptions

Class HtmlSaveOptions

java.lang.Object
com.grapecity.documents.excel.SaveOptionsBase
com.grapecity.documents.excel.drawing.HtmlSaveOptions

public class HtmlSaveOptions extends SaveOptionsBase
Represents options for saving a workbook as an HTML file.

Use this class to configure HTML-specific export settings such as tooltip text, CSS export behavior, worksheet export options, attached-file URLs, and related output behavior before saving workbook content as HTML.


 worksheet.getRange("A1:D4").setValue(new Object[][] {
     {"Region", "Q1", "Q2", "Q3"},
     {"North", 120, 130, 140}
 });
 worksheet.setName("QuarterlyReport");
 HtmlSaveOptions options = new HtmlSaveOptions();
 options.setExportHeadings(true);
 options.setExportGridlines(true);
 options.setExportArea("A1:D4");
 options.setExportSheetName("QuarterlyReport");
 ByteArrayOutputStream stream = new ByteArrayOutputStream();
 workbook.save(stream, options);
 
  • Constructor Details

    • HtmlSaveOptions

      public HtmlSaveOptions()
      Creates options for saving a workbook as an HTML file.

      This constructor initializes a new HtmlSaveOptions instance and sets its file format to SaveFileFormat.Html. Use the created object to configure HTML-specific export settings before saving.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setExportSingleTab(true);
       options.setAddTooltipText(true);
       workbook.save("path/to/output.html", options);
       
  • Method Details

    • getAddTooltipText

      public final boolean getAddTooltipText()
      Gets whether tooltip text is added when data cannot be fully displayed in the exported HTML.

      The default value is false.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setAddTooltipText(true);
       boolean addTooltipText = options.getAddTooltipText();
       workbook.save("path/to/output.html", options);
       
      Returns:
      true if tooltip text is added for truncated data in the exported HTML; otherwise, false.
    • setAddTooltipText

      public final void setAddTooltipText(boolean value)
      Sets whether tooltip text is added when data cannot be fully displayed in the exported HTML.

      The default value is false.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setAddTooltipText(true);
       workbook.save("path/to/output.html", options);
       
      Parameters:
      value - true if tooltip text is added for truncated data in the exported HTML; otherwise, false.
    • getExportFileName

      public final String getExportFileName()
      Gets the name of the HTML file.

      This property is used only when saving to a ZIP stream. The default value is "workbook".

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setExportFileName("report");
       String fileName = options.getExportFileName();
       workbook.save("path/to/output.html", options);
       
      Returns:
      The name of the HTML file used when saving to a ZIP stream. Returns "workbook" if no custom name has been set.
    • setExportFileName

      public final void setExportFileName(String value)
      Sets the name of the HTML file.

      This property is used only when saving to a ZIP stream. The default value is "workbook".

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setExportFileName("report");
       workbook.save("path/to/output.html", options);
       
      Parameters:
      value - The name of the HTML file used when saving to a ZIP stream. Sets "workbook" if no custom name has been set.
    • getAttachedFilesUrlPrefix

      public final String getAttachedFilesUrlPrefix()
      Gets the URL prefix of attached files, such as images, in the HTML file.

      This value is used when generating URLs for files that are exported alongside the HTML content. If no prefix has been specified, this method returns null.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setAttachedFilesUrlPrefix("resources/");
       String urlPrefix = options.getAttachedFilesUrlPrefix();
       workbook.save("path/to/output.html", options);
       
      Returns:
      The URL prefix for attached files, or null if no prefix has been specified.
    • setAttachedFilesUrlPrefix

      public final void setAttachedFilesUrlPrefix(String value)
      Sets the URL prefix of attached files, such as images, in the HTML file.

      This value is used when generating URLs for files that are exported alongside the HTML content. If no prefix has been specified, this method Sets null.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setAttachedFilesUrlPrefix("resources/");
       workbook.save("path/to/output.html", options);
       
      Parameters:
      value - The URL prefix for attached files, or null if no prefix has been specified.
    • getCellCssPrefix

      public final String getCellCssPrefix()
      Gets the prefix of the CSS class names used in exported HTML.

      The default value is null.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setCellCssPrefix("cell-");
       String cssPrefix = options.getCellCssPrefix();
       workbook.save("path/to/output.html", options);
       
      Returns:
      The prefix of the CSS class names. Returns null if no prefix is specified.
    • setCellCssPrefix

      public final void setCellCssPrefix(String value)
      Sets the prefix of the CSS class names used in exported HTML.

      The default value is null.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setCellCssPrefix("cell-");
       workbook.save("path/to/output.html", options);
       
      Parameters:
      value - The prefix of the CSS class names. Sets null if no prefix is specified.
    • getEncoding

      public final String getEncoding()
      Gets the encoding used when exporting to HTML.

      If no encoding has been set, the default value is UTF-8.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setEncoding("UTF-16");
       String encoding = options.getEncoding();
       workbook.save("path/to/output.html", options);
       
      Returns:
      The encoding name used for HTML export. Returns UTF-8 by default.
    • setEncoding

      public final void setEncoding(String value)
      Sets the encoding used when exporting to HTML.

      If no encoding has been set, the default value is UTF-8.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setEncoding("UTF-16");
       workbook.save("path/to/output.html", options);
       
      Parameters:
      value - The encoding name used for HTML export. Sets UTF-8 by default.
    • getExportDocumentProperties

      public final boolean getExportDocumentProperties()
      Gets whether document properties are exported when saving to HTML.

      This option controls whether the workbook's document properties are included in the generated HTML output. The default value is true. Use setExportDocumentProperties(boolean) to change this setting.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setExportDocumentProperties(false);
       boolean exportDocumentProperties = options.getExportDocumentProperties();
       workbook.save("path/to/output.html", options);
       
      Returns:
      true if document properties are exported to HTML; otherwise, false.
    • setExportDocumentProperties

      public final void setExportDocumentProperties(boolean value)
      Sets whether document properties are exported when saving to HTML.
      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setExportDocumentProperties(false);
       workbook.save("path/to/output.html", options);
       
      Parameters:
      value - true if document properties are exported to HTML; otherwise, false.
    • getExportGridlines

      public final boolean getExportGridlines()
      Gets whether gridlines are exported when saving to HTML.

      The default value is false.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setExportGridlines(true);
       boolean exportGridlines = options.getExportGridlines();
       workbook.save("path/to/output.html", options);
       
      Returns:
      true if worksheet gridlines are exported to HTML; otherwise, false.
    • setExportGridlines

      public final void setExportGridlines(boolean value)
      Sets whether gridlines are exported when saving to HTML.

      The default value is false.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setExportGridlines(true);
       workbook.save("path/to/output.html", options);
       
      Parameters:
      value - true if worksheet gridlines are exported to HTML; otherwise, false.
    • getExportHeadings

      public final boolean getExportHeadings()
      Gets whether headings are exported when saving a file to HTML.

      This property controls whether row and column headings are included in the exported HTML output. The default value is false.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setExportHeadings(true);
       boolean exportHeadings = options.getExportHeadings();
       workbook.save("path/to/output.html", options);
       
      Returns:
      true if headings are exported when saving to HTML; otherwise, false.
    • setExportHeadings

      public final void setExportHeadings(boolean value)
      Sets whether headings are exported when saving a file to HTML.

      This property controls whether row and column headings are included in the exported HTML output. The default value is false.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setExportHeadings(true);
       workbook.save("path/to/output.html", options);
       
      Parameters:
      value - true if headings are exported when saving to HTML; otherwise, false.
    • getExportHiddenWorksheet

      public final boolean getExportHiddenWorksheet()
      Gets whether hidden worksheets are exported when saving to HTML.

      The default value is false.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setExportHiddenWorksheet(true);
       boolean exportHiddenWorksheet = options.getExportHiddenWorksheet();
       workbook.save("path/to/output.html", options);
       
      Returns:
      true if hidden worksheets are exported when saving to HTML; otherwise, false.
    • setExportHiddenWorksheet

      public final void setExportHiddenWorksheet(boolean value)
      Sets whether hidden worksheets are exported when saving to HTML.

      The default value is false.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setExportHiddenWorksheet(true);
       workbook.save("path/to/output.html", options);
       
      Parameters:
      value - true if hidden worksheets are exported when saving to HTML; otherwise, false.
    • getExportImageAsBase64

      public final boolean getExportImageAsBase64()
      Gets whether images are saved in Base64 format to html.

      The default value is false. When this property is true, image data is exported directly on the img elements and separate files are not created.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setExportImageAsBase64(true);
       boolean exportImageAsBase64 = options.getExportImageAsBase64();
       workbook.save("path/to/output.html", options);
       
      Returns:
      true if images are saved in Base64 format to html; otherwise, false.
    • setExportImageAsBase64

      public final void setExportImageAsBase64(boolean value)
      Sets whether images are saved in Base64 format to html.

      The default value is false. When this property is true, image data is exported directly on the img elements and separate files are not created.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setExportImageAsBase64(true);
       workbook.save("path/to/output.html", options);
       
      Parameters:
      value - true if images are saved in Base64 format to html; otherwise, false.
    • getExportCssSeparately

      @Deprecated public final boolean getExportCssSeparately()
      Deprecated.
      Use getCssExportType() instead.
      Gets whether the worksheet style is exported to CSS separately.

      The default value is true. When this property is false, CSS style data is exported directly to each worksheet and a separate stylesheet.css file is not created.

      Returns:
      true if the worksheet style is exported to a separate CSS file; otherwise, false.
    • setExportCssSeparately

      @Deprecated public final void setExportCssSeparately(boolean value)
      Deprecated.
      Sets whether the worksheet style is exported to CSS separately.

      The default value is true. When this property is false, CSS style data is exported directly to each worksheet and a separate stylesheet.css file is not created.

      Parameters:
      value - true if the worksheet style is exported to a separate CSS file; otherwise, false.
    • getExportSingleTab

      public final boolean getExportSingleTab()
      Gets whether a single HTML tab is exported when the workbook contains only one worksheet or when setExportSheetName(String) specifies a worksheet to export.

      The default value is false.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setExportSingleTab(true);
       boolean exportSingleTab = options.getExportSingleTab();
       workbook.save("path/to/output.html", options);
       
      Returns:
      true if a single HTML tab is exported when the workbook has only one worksheet or an export sheet name is specified; otherwise, false.
    • setExportSingleTab

      public final void setExportSingleTab(boolean value)
      Sets whether a single HTML tab is exported when the workbook contains only one worksheet or when setExportSheetName(String) specifies a worksheet to export.

      The default value is false.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setExportSingleTab(true);
       workbook.save("path/to/output.html", options);
       
      Parameters:
      value - true if a single HTML tab is exported when the workbook has only one worksheet or an export sheet name is specified; otherwise, false.
    • getIsExportComments

      public final boolean getIsExportComments()
      Gets whether comments are exported when saving to HTML.

      This option applies to HTML export and determines whether cell comments are included in the generated HTML output. The default value is false.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setIsExportComments(true);
       boolean exportComments = options.getIsExportComments();
       workbook.save("path/to/output.html", options);
       
      Returns:
      true if comments are exported when saving to HTML; otherwise, false.
    • setIsExportComments

      public final void setIsExportComments(boolean value)
      Sets whether comments are exported when saving to HTML.

      This option applies to HTML export and determines whether cell comments are included in the generated HTML output. The default value is false.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setIsExportComments(true);
       workbook.save("path/to/output.html", options);
       
      Parameters:
      value - true if comments are exported when saving to HTML; otherwise, false.
    • getIsFullPathLink

      public final boolean getIsFullPathLink()
      Gets whether full path links are used in exported HTML.

      This property applies only when exporting to an HTML file. The default value is false.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setIsFullPathLink(true);
       boolean isFullPathLink = options.getIsFullPathLink();
       workbook.save("path/to/output.html", options);
       
      Returns:
      true if hyperlinks in the exported HTML use full paths; otherwise, false.
    • setIsFullPathLink

      public final void setIsFullPathLink(boolean value)
      Sets whether full path links are used in exported HTML.

      This property applies only when exporting to an HTML file. The default value is false.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setIsFullPathLink(true);
       workbook.save("path/to/output.html", options);
       
      Parameters:
      value - true if hyperlinks in the exported HTML use full paths; otherwise, false.
    • getLinkTargetType

      public final HyperLinkTargetType getLinkTargetType()
      Gets the target attribute type for hyperlinks in exported HTML. The default value is HyperLinkTargetType.Blank.
      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setLinkTargetType(HyperLinkTargetType.Self);
       HyperLinkTargetType linkTargetType = options.getLinkTargetType();
       ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
       workbook.save(outputStream, options);
       
      Returns:
      The target attribute type for hyperlinks in exported HTML.
    • setLinkTargetType

      public final void setLinkTargetType(HyperLinkTargetType value)
      Sets the target attribute type for hyperlinks in exported HTML.

      Use this method to control how generated hyperlinks are opened in the target environment, such as in the same frame, parent frame, or a new window or tab.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setLinkTargetType(HyperLinkTargetType.Self);
       workbook.save("path/to/output.html", options);
       
      Parameters:
      value - The hyperlink target type to apply to exported HTML links.
    • getPageTitle

      public final String getPageTitle()
      Gets the title of the HTML page.

      Use this method to retrieve the page title configured by setPageTitle(String) for HTML export.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setPageTitle("Sales Report");
       String pageTitle = options.getPageTitle();
       workbook.save("path/to/output.html", options);
       
      Returns:
      The title of the HTML page.
    • setPageTitle

      public final void setPageTitle(String value)
      Sets the title of the HTML page.
      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setPageTitle("Sales Report");
       workbook.save("path/to/output.html", options);
       
      Parameters:
      value - The title of the HTML page.
    • getTableCssId

      public final String getTableCssId()
      Gets the prefix of the type CSS names, such as tr and td, that are contained in the table element with the specific TableCssId attribute.

      The default value is null.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setTableCssId("salesTable");
       String tableCssId = options.getTableCssId();
       workbook.save("path/to/output.html", options);
       
      Returns:
      The prefix of the type CSS names for the table element with the specific TableCssId attribute, or null if it is not set.
    • setTableCssId

      public final void setTableCssId(String value)
      Sets the prefix of the type CSS names, such as tr and td, that are contained in the table element with the specific TableCssId attribute.

      The default value is null.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setTableCssId("salesTable");
       workbook.save("path/to/output.html", options);
       
      Parameters:
      value - The prefix of the type CSS names for the table element with the specific TableCssId attribute, or null if it is not set.
    • getIsWidthScalable

      public final boolean getIsWidthScalable()
      Gets whether scalable units are used to describe column widths when exporting to HTML.

      This option controls how column width information is written during HTML export. The default value is false. See setIsWidthScalable(boolean).

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setIsWidthScalable(true);
       boolean isWidthScalable = options.getIsWidthScalable();
       workbook.save("path/to/output.html", options);
       
      Returns:
      true if scalable units are used for column widths during HTML export; otherwise, false.
    • setIsWidthScalable

      public final void setIsWidthScalable(boolean value)
      Sets whether scalable units are used to describe column widths when exporting to HTML.
      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setIsWidthScalable(true);
       workbook.save("path/to/output.html", options);
       
      Parameters:
      value - true if scalable units are used for column widths during HTML export; otherwise, false.
    • getExportSheetName

      public final String getExportSheetName()
      Gets the name of the worksheet to export to HTML.

      Use this property to determine which worksheet has been selected for HTML export. This setting is used when exporting a specific worksheet from a workbook.

      
       worksheet.setName("QuarterlyReport");
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setExportSheetName("QuarterlyReport");
       String sheetName = options.getExportSheetName();
       workbook.save("path/to/output.html", options);
       
      Returns:
      The name of the worksheet configured for HTML export.
    • setExportSheetName

      public final void setExportSheetName(String value)
      Sets the name of the worksheet to export to HTML.

      Use this property to specify which worksheet has been selected for HTML export.

      
       worksheet.setName("QuarterlyReport");
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setExportSheetName("QuarterlyReport");
       workbook.save("path/to/output.html", options);
       
      Parameters:
      value - The name of the worksheet configured for HTML export.
    • getExportArea

      public final String getExportArea()
      Gets which area is exported to HTML.

      This property is used to export a specific area of a worksheet. It only takes effect when getExportSheetName() is not null. Use setExportArea(String) to specify the area reference, such as "A2:G23".

      
       worksheet.setName("QuarterlyReport");
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setExportSheetName("QuarterlyReport");
       options.setExportArea("A1:D4");
       String exportArea = options.getExportArea();
       workbook.save("path/to/output.html", options);
       
      Returns:
      The area reference configured for HTML export.
    • setExportArea

      public final void setExportArea(String value)
      Sets which area is exported to HTML.
      
       worksheet.setName("QuarterlyReport");
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setExportSheetName("QuarterlyReport");
       options.setExportArea("A1:D4");
       workbook.save("path/to/output.html", options);
       
      Parameters:
      value - The area reference configured for HTML export.
    • getCssExportType

      public final CssExportType getCssExportType()
      Gets the way in which the stylesheet (CSS) is exported.
      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setCssExportType(CssExportType.External);
       CssExportType cssExportType = options.getCssExportType();
       workbook.save("path/to/output.html", options);
       
      Returns:
      The way in which the stylesheet (CSS) is exported.
    • setCssExportType

      public final void setCssExportType(CssExportType value)
      Sets the way in which the stylesheet (CSS) is exported.

      Use CssExportType to control whether CSS is exported to an external CSS file, within the HTML style tag, or as inline style attributes on HTML elements.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setCssExportType(CssExportType.External);
       workbook.save("path/to/output.html", options);
       
      Parameters:
      value - The CSS export type.
    • getIncludeAutoMergedCells

      public final boolean getIncludeAutoMergedCells()
      Gets whether automatically merged cells are included when exporting to HTML.

      This option applies to auto-merge information added by IWorksheet.autoMerge(com.grapecity.documents.excel.IRange,com.grapecity.documents.excel.AutoMergeDirection,com.grapecity.documents.excel.AutoMergeMode,com.grapecity.documents.excel.AutoMergeSelectionMode). The default value is false.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setIncludeAutoMergedCells(true);
       boolean includeAutoMergedCells = options.getIncludeAutoMergedCells();
       workbook.save("path/to/output.html", options);
       
      Returns:
      true if automatically merged cells are included when exporting to HTML; otherwise, false.
    • setIncludeAutoMergedCells

      public final void setIncludeAutoMergedCells(boolean value)
      Sets whether automatically merged cells are included when exporting to HTML.

      This option applies to auto-merge information added by IWorksheet.autoMerge(com.grapecity.documents.excel.IRange,com.grapecity.documents.excel.AutoMergeDirection,com.grapecity.documents.excel.AutoMergeMode,com.grapecity.documents.excel.AutoMergeSelectionMode). The default value is false.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       options.setIncludeAutoMergedCells(true);
       workbook.save("path/to/output.html", options);
       
      Parameters:
      value - true if automatically merged cells are included when exporting to HTML; otherwise, false.
    • getCellAttributeOptions

      public Map<CellAttribute,String> getCellAttributeOptions()
      Gets the options for cell element attributes when exporting to HTML.

      The returned map uses CellAttribute values as keys and the corresponding HTML attribute names as values. You can use this map to inspect or modify which attributes are written to exported cell elements.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       Map<CellAttribute, String> cellAttributeOptions = options.getCellAttributeOptions();
       cellAttributeOptions.put(CellAttribute.Address, "address");
       workbook.save("path/to/output.html", options);
       
      Returns:
      A map where the key is a CellAttribute and the value is a string representing the attribute's name.
    • setCellAttributeOptions

      public void setCellAttributeOptions(Map<CellAttribute,String> value)
      Sets the options for cell element attributes when exporting to HTML.

      Provide a map whose keys specify which CellAttribute values to export and whose values specify the HTML attribute names written to the exported cell elements. Set this property to null to clear the custom cell attribute mappings.

      
       HtmlSaveOptions options = new HtmlSaveOptions();
       Map<CellAttribute, String> cellAttributeOptions = new HashMap<>();
       cellAttributeOptions.put(CellAttribute.Address, "data-address");
       options.setCellAttributeOptions(cellAttributeOptions);
       workbook.save("path/to/output.html", options);
       
      Parameters:
      value - A map where each key identifies a cell attribute to export and each value specifies the HTML attribute name to write for that attribute. null clears the custom cell attribute mappings.