Export Worksheet CSS Separately in Output HTML
Possible Usage Scenarios
Aspose.Cells provides the feature to export worksheet CSS separately when you convert your Excel file to HTML. Please use HtmlSaveOptions.ExportWorksheetCSSSeparately property for this purpose and set it to true while saving Excel file to HTML format.
Export Worksheet CSS Separately in Output HTML
The following sample code creates an Excel file, adds some text in cell B5 in Red color and then saves it in HTML format using HtmlSaveOptions.ExportWorksheetCSSSeparately property. Please see the output HTML generated by the code for reference. You will find stylesheet.css inside it as an outcome of the sample code.
Sample Code
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
//Create workbook object | |
Workbook wb = new Workbook(); | |
//Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
//Access cell B5 and put value inside it | |
Cell cell = ws.Cells["B5"]; | |
cell.PutValue("This is some text."); | |
//Set the style of the cell - font color is Red | |
Style st = cell.GetStyle(); | |
st.Font.Color = Color.Red; | |
cell.SetStyle(st); | |
//Specify html save options - export worksheet css separately | |
HtmlSaveOptions opts = new HtmlSaveOptions(); | |
opts.ExportWorksheetCSSSeparately = true; | |
//Save the workbook in html | |
wb.Save("outputExportWorksheetCSSSeparately.html", opts); |
Export single sheet workbook to HTML
When a workbook with multiple sheets is converted to HTML using Aspose.Cells, it creates an HTML file along with a folder containing CSS and multiple HTML files. When this HTML file is opened in the browser, the tabs are visible. The same behavior is required for a workbook with single worksheet when it is converted to HTML. Earlier no separate folder was created for single sheet workbooks and only HTML file was created. Such HTML file does not show tab when opened in browser. MS Excel creates proper folder and HTML for a single sheet also and hence same behavior is implemented using Aspose.Cells APIs. The sample file can be downloaded from the following link for using in the sample code below:
Sample Code
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Load the sample Excel file containing single sheet only | |
Workbook wb = new Workbook(sourceDir + "sampleSingleSheet.xlsx"); | |
// Specify HTML save options | |
Aspose.Cells.HtmlSaveOptions options = new Aspose.Cells.HtmlSaveOptions(); | |
// Set optional settings if required | |
options.Encoding = System.Text.Encoding.UTF8; | |
options.ExportImagesAsBase64 = true; | |
options.ExportGridLines = true; | |
options.ExportSimilarBorderStyle = true; | |
options.ExportBogusRowData = true; | |
options.ExcludeUnusedStyles = true; | |
options.ExportHiddenWorksheet = true; | |
//Save the workbook in Html format with specified Html Save Options | |
wb.Save(outputDir + "outputSampleSingleSheet.htm", options); |