Options and methods that define HTML export behavior.
For a list of all members of this type, see HtmlExporterOptions Members.
System.Object
GemBox.Spreadsheet.HtmlExporterOptions
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.
Other than just properties, exporting process can be handled by user defined methods that can replace any of the default ones. User defined methods are simply passed as delegates.
Following code demonstrates how to use HtmlExporter. It shows next features:
[Visual Basic]
' Method that returns xml node from excel file.
Private Shared Function GetTableNodeFromExcelFile(ByVal fileName As String) As XmlNode
Dim ef As New ExcelFile
Dim options As New HtmlExporterOptions
ef.LoadXlsx(fileName, XlsxOptions.None)
' By default grid lines are showed.
options.ShowGridLines = False
' Overrides default MethodRowToHtml by assigning CustomRowToHtml to it.
' Default MethodRowToHtml is DefaultHtmlExporter.DefaultRowToHtml.
' Any method in exporting process can be overridden this way.
options.MethodRowToHtml = New RowToHtmlDelegate(AddressOf Program.CustomRowToHtml)
' Range that is exporting is set to used range of the first worksheet.
Dim range As CellRange = ef.Worksheets.Item(0).GetUsedCellRange
Return DefaultHtmlExporter.DefaultTableToHtml(options, range)
End Function
' Method that exports every row as default one, but for pair rows sets font style to bold.
Private Shared Function CustomRowToHtml(ByVal options As HtmlExporterOptions, ByVal row As ExcelRow, ByVal range As CellRange, ByVal htmlRowIndex As Integer) As XmlNode
' Default method can be called from anywhere, including methods that are overriding default ones.
Dim rowNode As XmlNode = DefaultHtmlExporter.DefaultRowToHtml(options, row, range, htmlRowIndex)
If ((htmlRowIndex Mod 2) = 0) Then
Dim styleAttribute As XmlAttribute = rowNode.Attributes.ItemOf("style")
' If style attribute don't exist, new style attribute is created.
If (styleAttribute Is Nothing) Then
styleAttribute = options.ExportingXmlDocument.CreateAttribute("style")
rowNode.Attributes.Append(styleAttribute)
End If
' Sets font-weight to bold.
styleAttribute.Value = (styleAttribute.Value & "font-weight:700;")
End If
Return rowNode
End Function
[C#]
// Method that returns xml node from excel file.
private static XmlNode GetTableNodeFromExcelFile(string fileName)
{
ExcelFile ef = new ExcelFile();
HtmlExporterOptions options = new HtmlExporterOptions();
ef.LoadXlsx(fileName, XlsxOptions.None);
// By default grid lines are showed.
options.ShowGridLines = false;
// Overrides default MethodRowToHtml by assigning CustomRowToHtml to it.
// Default MethodRowToHtml is DefaultHtmlExporter.DefaultRowToHtml.
// Any method in exporting process can be overridden this way.
options.MethodRowToHtml = CustomRowToHtml;
// Range that is exporting is set to used range of the first worksheet.
CellRange range = ef.Worksheets[0].GetUsedCellRange();
return DefaultHtmlExporter.DefaultTableToHtml(options, range);
}
// Method that exports every row as default one, but for pair rows sets font style to bold.
private static XmlNode CustomRowToHtml(HtmlExporterOptions options, ExcelRow row, CellRange range, int htmlRowIndex)
{
// Default method can be called from anywhere, including methods that are overriding default ones.
XmlNode rowNode = DefaultHtmlExporter.DefaultRowToHtml(options, row, range, htmlRowIndex);
if (htmlRowIndex % 2 == 0)
{
XmlAttribute styleAttribute = rowNode.Attributes["style"];
// If style attribute don't exist, new style attribute is created.
if (styleAttribute == null)
{
styleAttribute = options.ExportingXmlDocument.CreateAttribute("style");
rowNode.Attributes.Append(styleAttribute);
}
// Sets font-weight to bold.
styleAttribute.Value += "font-weight:700;";
}
return rowNode;
}
Namespace: GemBox.Spreadsheet
Assembly: GemBox.Spreadsheet (in GemBox.Spreadsheet.dll)
HtmlExporterOptions Members | GemBox.Spreadsheet Namespace