how to get current paragraph of .docx document under cursor?
Hello @softboy99
Please specify from which context you are trying to get the paragraph. Is it Macro or Plugin? Also, please specify version of Document Server/Desktop Editor you are using.
from plugin
version: 8.1.3
Firstly, used version of Document Server/Desktop Editor is outdated. I recommend updating the app.
As for the query: since there is no direct method to get paragraph without index, I believe an optimal approach would be to get sentence under the cursor first, then perform search and call for the paragraph to obtain its text. Here is an example:
(function (window, undefined) {
window.Asc.plugin.init = function () {
window.Asc.plugin.executeMethod("GetCurrentSentence", ["entirely"]); // Get sentence under the cursor
window.Asc.plugin.onMethodReturn = function (returnValue) {
Asc.scope.st = returnValue; // Define result of the previous method as a variable to pass to the callCommand
window.Asc.plugin.callCommand(function () {
var oDocument = Api.GetDocument();
var oSearch = oDocument.Search(Asc.scope.st); // Perform search
var oPara = oSearch[0].GetParagraph(0); // Get paragraph
var oParaContent = oPara.GetText(); // Get text of the paragraph
console.log(oParaContent);
});
};
};
window.Asc.plugin.button = function (id) {
};
})(window, undefined);
This example will return the text of the current paragraph that is referenced through the current sentence.
Used methods: GetCurrentSentence, Search, GetParagraph, GetText.
Also, for the reference here are the links on how to call methods and how to call commands as they basically essential for understanding how plugins work.
Hi,
how about new blank line?there is no any Sentence. Anther problem, how do you know the destination is the first one after search?var oPara = oSearch[0].GetParagraph(0);
That was never mentioned. As I don’t see full usage scenario, I cannot suggest suitable for your approach. Please elaborate on your goals in as much details as possible.
By the way, do I understand correctly that the query in mentioned below topic also refers to the use case of this one?