Hi there, are there any plans to support RichText in the Excel JS API? As of right now it looks like I can only set formatting for the entire cell and not specific pieces of text within the cell. If ...
AdrianWu
Microsoft
Dec 12, 2024Hi! Thank you for your patience. The requested rich text support feature has been implemented and will be included in the upcoming Excel requirement set 1.18 release, scheduled for February 2025. In the meantime, you can already experiment with these capabilities in the beta build.
The following APIs will be available:
- Excel.CellPropertiesInternal.TextRuns
- Excel.CellPropertiesLoadOptionsInternal.TextRuns
- Excel.RangeTextRun.Text
- Excel.RangeTextRun.Font
For more details, please refer to the official documentation. Below is a sample code snippet that demonstrates how you can use rich text formatting in cells:
(async () => {
await Excel.run(async (context) => {
var sheet = context.workbook.worksheets.getItem("TestSheet");
const cellSrc = sheet.getRange("A1");
const cellSrcTextRun: Excel.SettableCellProperties = {
textRuns: [
{ text: "Sample", font: { bold: true, color: "#00B0F0", size: 14, italic: true } },
{ text: "1", font: { subscript: true } },
{ text: "String" },
{ text: "2", font: { superscript: true, color: "black", tintAndShade: 0.5 } },
],
};
cellSrc.clear(Excel.ClearApplyTo.all);
cellSrc.setCellProperties([[cellSrcTextRun]]);
await context.sync();
const textRunCellProperty = cellSrc.getCellProperties({ textRuns: true });
await context.sync();
const cellTextRuns = textRunCellProperty.value[0][0].textRuns;
console.log(JSON.stringify(cellTextRuns, undefined, " "));
});
})();
If you have any further questions or feedback, feel free to let us know!