https://github.com/OfficeDev/office-js/issues/4623#issuecomment-2537948014
Hi @KaranLala
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, " "));
});
})();
_
반응형