How to get cell formatting using Office.js

I am developing an Excel add-in that extracts the text of cell A1, INCLUDING its format, and displays the text in its area. Thus, the appendix contains this (see screenshot below): • Area for displaying formatted text • Button for starting extraction Press to view image

Below is the code I use to get the text

function displaySelectedCells() {
    Office.context.document.getSelectedDataAsync(Office.CoercionType.Text,
        function (result) {
            if (result.status === Office.AsyncResultStatus.Succeeded) {
                showNotification('The selected text is:', '"' + result.value + '"');
            } else {
                showNotification('Error', result.error.message);
            }
        });
}

The code above uses "CoercionType" as "Text." I tried a lot to find a solution for getting text in the format written in the sheet cell. The answer I get is just the text on the plane :( Please help me solve the problem

+4
2

: myRange.format.font.load(['bold','color','italic','name','size','underline']), , , .., , myRange, , , ( ), , , , , . API- .

, , HTML . UserVoice (https://officespdev.uservoice.com/), , .

~ , Office Extensibility, MSFT

0

, , RangeFont, Range.format.font. :

Excel.run(function (ctx) { 
    var myRange = ctx.workbook.getSelectedRange();
    var myFont = myRange.format.font;
    myFont.load(['bold','color','italic','name','size','underline']);
    myRange.load('values');
    return ctx.sync().then(function() {
        log(myFont.color);
        log(myFont.bold);
        log(myRange.values);
    });
}).catch(function(error) {
    log("Error: " + error);
});
0

All Articles