Do you want to: Report a bug
Document Server version:8.1.1.26
Additional information:
I have a sample .pptx file where I want to write a macro that’ll search a paragraph for a specific word and then highlight the hits. However, when I retrieve the paragraphs from a Slide and call the Search method, I get an exception that’s coming from sdk-all.js itself.
This seems like a bug, since it’s coming from the sdk itself. Moreover, if I create a copy by calling the Copy method on the paragraph and try to search the copy instead, I don’t get the exception. However, the copy still doesn’t return search results, even if I pass a string that’s present in said paragraph.
Steps to reproduce:
-
Open the following file samplepptx.pptx in onlyoffice’s presentation editor. Link to file: samplepptx
-
Go to the plugins menu, and then click on macro
-
Open dev tools from your browser (on chrome and firefox, hit F12) and go to console
-
In the macro window, paste the following script and click on run. You should get some exceptions as mentioned.
(function()
{
var oPresentation = Api.GetPresentation();
for(let i = 0; i < oPresentation.GetSlidesCount(); i++){
let slide = oPresentation.GetSlideByIndex(i);
let shapes = slide.GetAllShapes();
shapes.forEach(shape =>{
var shapeContent = shape.GetContent();
for(let j = 0; j < shapeContent.GetElementsCount(); j++){
var element = shapeContent.GetElement(j);
if(element.GetClassType() === 'paragraph'){
var text = element.GetText();
console.log(text);
var query = "Cloud";
try{
var hits = element.Search(query);
console.log('hits: ')
console.log(hits);
}
catch(error){
console.log('error in this paragraph:')
console.log(error)
console.log('searching in copy instead...')
//Search a copy instead
var copy = element.Copy();
var hitsInCopy = copy.Search(query)
console.log(hitsInCopy)
}
console.log('')
}
}
});
}
})();