Reputation: 83
I created an Add-In App for Office365 (Word, Excel and Powerpoint) and i want to get the selected text inside my app, with new lines and styling.
I am using the following code to do that
function getSelectedData(hasSelectionCallback, noSelectionCallback) {
var type = Office.CoercionType.Text;
Office.context.document.getSelectedDataAsync(type,
{
valueFormat: "formatted", filterType: "all"
},
function (asyncResult) {
var error = asyncResult.error;
if (asyncResult.status === Office.AsyncResultStatus.Failed)
{
console.log(error.name + ": " + error.message);
}
else {
// Get selected data.
}
});
}
I tried with all types of Coercion but none does what i actually need.
For example, i want to parse the selected data, so i can know where the new lines are.
For the moment it only returns plain text, with no formatting or styling.
I would appreciate a response for my problem.
Thank you!
Upvotes: 1
Views: 261
Reputation: 5036
this is an interesting question. The quick answer to it is that the valueFormat optional parameter of the getSelectedDataAsync method is
I would encourage you to try the new Word And Excel API to get formatting information.
check out a sample for Word here on how you can get the selection formatting details as well of a specific paragraph.
also check this out for range formatting in Excel.
Hope this helps!
Upvotes: 1
Reputation: 8670
In Word, there is the OpenXML (Office.CoercionType.Ooxml
) coercion, which will give you everything there is to know about the selection. OOXML is somewhat verbose, but as detailed as you can possibly wish for.
For Excel and PowerPoint, I believe that all you can get is plain text, not any formatting info (though I'm a little surprised you don't get newline info, that seems like it's part of text content rather than formatting...)
Hope this helps!
Upvotes: 0