在字体上应用上标和下标效果
Contents
[
Hide
]
Aspose.Cells提供将文本应用上标(文本位于基线上方)和下标(文本位于基线下方)效果的功能。
处理上标和下标
通过将 Font 对象的 setIsSuperscript 方法设置为 true 来应用上标效果。要应用下标,将 Font 对象的 setIsSubscript 方法设置为 true。
以下代码示例展示了如何将上标和下标应用于文本。
使用 Node.js 代码在文本上应用上标效果
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require("path"); | |
const AsposeCells = require("aspose.cells.node"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Create directory if it is not already present. | |
const fs = require("fs"); | |
if (!fs.existsSync(dataDir)) { | |
fs.mkdirSync(dataDir); | |
} | |
// Instantiating a Workbook object | |
const workbook = new AsposeCells.Workbook(); | |
// Adding a new worksheet to the Excel object | |
workbook.getWorksheets().add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
const worksheet = workbook.getWorksheets().get(0); | |
// Accessing the "A1" cell from the worksheet | |
const cell = worksheet.getCells().get("A1"); | |
// Adding some value to the "A1" cell | |
cell.putValue("Hello"); | |
// Setting the font Superscript | |
const style = cell.getStyle(); | |
style.getFont().setIsSuperscript(true); | |
cell.setStyle(style); | |
// Saving the Excel file | |
workbook.save(path.join(dataDir, "Superscript.out.xls"), AsposeCells.SaveFormat.Auto); |
使用 Node.js 代码在文本上应用下标效果
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require("path"); | |
const AsposeCells = require("aspose.cells.node"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Create directory if it is not already present. | |
const fs = require('fs'); | |
if (!fs.existsSync(dataDir)) { | |
fs.mkdirSync(dataDir); | |
} | |
// Instantiating a Workbook object | |
const workbook = new AsposeCells.Workbook(); | |
// Adding a new worksheet to the Excel object | |
workbook.getWorksheets().add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
const worksheet = workbook.getWorksheets().get(0); | |
// Accessing the "A1" cell from the worksheet | |
const cell = worksheet.getCells().get("A1"); | |
// Adding some value to the "A1" cell | |
cell.putValue("Hello"); | |
// Setting the font Subscript | |
const style = cell.getStyle(); | |
style.getFont().setIsSubscript(true); | |
cell.setStyle(style); | |
// Saving the Excel file | |
workbook.save(path.join(dataDir, "Subscript.out.xls"), AsposeCells.SaveFormat.Auto); |