Export Worksheet CSS Separately in Output HTML with Node.js via C++

Possible Usage Scenarios

Aspose.Cells for Node.js via C++ provides the feature to export worksheet CSS separately when you convert your Excel file to HTML. Please use HtmlSaveOptions.getExportWorksheetCSSSeparately() property for this purpose and set it to true while saving the 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.getExportWorksheetCSSSeparately() 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

const AsposeCells = require("aspose.cells.node");
const path = require("path");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "sample.xlsx");

// Create workbook object
const wb = new AsposeCells.Workbook();

// Access first worksheet
const ws = wb.getWorksheets().get(0);

// Access cell B5 and put value inside it
const cell = ws.getCells().get("B5");
cell.putValue("This is some text.");

// Set the style of the cell - font color is Red
const st = cell.getStyle();
st.getFont().setColor(AsposeCells.Color.Red);
cell.setStyle(st);

// Specify html save options - export worksheet css separately
const opts = new AsposeCells.HtmlSaveOptions();
opts.setExportWorksheetCSSSeparately(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 for Node.js via C++, 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 a single worksheet when it is converted to HTML. Earlier, no separate folder was created for single sheet workbooks, and only an HTML file was created. Such an HTML file does not show tabs when opened in the browser. MS Excel creates a proper folder and HTML for a single sheet also, and hence the same behavior is implemented using Aspose.Cells APIs. The sample file can be downloaded from the following link for use in the sample code below:

sampleSingleSheet.xlsx

Sample Code

const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const sourceFilePath = path.join(dataDir, "sampleSingleSheet.xlsx");
// Load the sample Excel file containing single sheet only
const wb = new AsposeCells.Workbook(sourceFilePath);

// Specify HTML save options
const options = new AsposeCells.HtmlSaveOptions();

// Set optional settings if required
options.setEncoding(AsposeCells.EncodingType.UTF8);
options.setExportImagesAsBase64(true);
options.setExportGridLines(true);
options.setExportSimilarBorderStyle(true);
options.setExportBogusRowData(true);
options.setExcludeUnusedStyles(true);
options.setExportHiddenWorksheet(true);

// Save the workbook in Html format with specified Html Save Options
wb.save(path.join(dataDir, "outputSampleSingleSheet.htm"), options);