Options and methods that define HTML export behavior.
Namespace: GemBox.SpreadsheetAssembly: GemBox.Spreadsheet (in GemBox.Spreadsheet.dll) Version: 35.0.30.1025
Syntax
| C# |
|---|
public class HtmlExporterOptions |
| Visual Basic |
|---|
Public Class HtmlExporterOptions |
Remarks
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.
Examples
Following code demonstrates how to use HtmlExporter. It shows next features:
CopyVB.NET
CopyC#
- Export excel table (only used range) as HTML table node
- Override DefaultRowToHtml method
' 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
// 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; }