管理单元格HTML字符串

可能的使用场景

当您需要为特定单元格设置样式化数据时,可以将 HTML 字符串分配给单元格。当然,也可以获取单元格的 HTML 字符串。Aspose.Cells for Node.js via C++ 提供了此功能。Aspose.Cells 提供了以下属性和方法,帮助您实现目标。

使用 Aspose.Cells for Node.js via C++ 获取和设置 HTML 字符串

此示例演示如何:

  1. 创建一个工作簿并添加一些数据。
  2. 获取第一个工作表中的特定单元格。
  3. 设置 HTML 字符串到单元格。
  4. 获取单元格的 HTML 字符串。
const AsposeCells = require("aspose.cells.node");
const path = require("path");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Instantiating a Workbook object
let workbook = new AsposeCells.Workbook();
// Obtaining the reference of the newly added worksheet
let ws = workbook.getWorksheets().get(0);
let cells = ws.getCells();
// Setting the value to the cells
let cell = cells.get("A1");
cell.putValue("Fruit");
cell = cells.get("B1");
cell.putValue("Count");
cell = cells.get("C1");
cell.putValue("Price");
cell = cells.get("A2");
cell.putValue("Apple");
cell = cells.get("A3");
cell.putValue("Mango");
cell = cells.get("A4");
cell.putValue("Blackberry");
cell = cells.get("A5");
cell.putValue("Cherry");
let c3 = cells.get("C3");
// set html string for C3 cell.
c3.setHtmlString("<b>test bold</b>");
let c4 = cells.get("C4");
// set html string for C4 cell.
c4.setHtmlString("<i>test italic</i>");
// get the html string of specific cell.
console.log(c3.getHtmlString());
console.log(c4.getHtmlString());

示例代码生成的输出

以下截图显示了上述示例代码的输出。

todo:image_alt_text