현재 office-js api를 사용하여 단어 문서를 검색하고 doc라는 단어에 배치 된 토큰의 모든 인스턴스를 찾습니다. 그러나 일치하는 토큰을 교체하려고 할 때 debug.errorlocation = "Range.insertParagraph"
. 작업이 작성된 방식대로 작동해야하는 것처럼 보이지만 검색 결과가 발견 될 때 원하는 단어를 대체하지 않습니다.
샘플 문자열
Our strategy is to consider ~~client~~'s business needs, and our audit will specifically focus on these related key factors:
암호
Word.run(function (context) {
var content = contentObject.Content.replace(/<img[^>"']*((("[^"]*")|('[^']*'))[^"'>]*)*>/g, "");
var range = context.document.getSelection().insertHtml(content, Word.InsertLocation.replace);
var paragraphs = context.document.body.paragraphs;
var clientName;
paragraphs.load(paragraphs, range, 'text');
return context.sync().then(function () {
for (var x = 0; x < paragraphs.items.length; x++) {
var paragraph = paragraphs.items[x];
var styleType = paragraphs.items[x].text.toString().match(/~~([^]*?)~~/g);
if (paragraphs.items[x].text.search("~~") >= 0 && styleType[0] != "~~/picture~~") {
var styleValue = styleType[0].toString().replace(/[\]~~)}[{(]/g, '').trim();
paragraph.style = styleValue;
}
if(paragraphs.items[x].style === "/Title Page Client Name")
{
var name = paragraphs.items[x].text;
clientName = name;
}
}
return context.sync().then(function () {
var searchResults = context.document.body.search('~~client~~', { ignoreSpace: true });
context.load(searchResults);
return context.sync().then(function () {
for (var i = 0; i < searchResults.items.length; i++) {
error location>> searchResults.items[i].insertParagraph(clientName, Word.InsertLocation.replace);
}
clientName = "";
})
})
})
.then(context.sync)
.then(cleanTags())
.catch(function (error) {
feedBackMessage(error.description);
})
});
};
좋아, 나에게 오류를 일으키는 문제 .insertParagraph
는 단어 api가 단어가 아닌 단락 삽입을 예상하는 곳에서 사용하고 있다는 것 입니다. 이 API가 실제로 단락과 간단한 텍스트 삽입을 감지 할 수있을만큼 충분히 설계되어 있다는 것이 대단하다고 생각합니다. 기록을 위해 누군가 텍스트 (단어 한 단어 만)를 삽입하려는 경우 .insertText
.
문구 코드
return context.sync().then(function () {
var searchResults = context.document.body.search('~~client~~', { ignoreSpace: true });
context.load(searchResults);
return context.sync().then(function () {
for (var i = 0; i < searchResults.items.length; i++) {
searchResults.items[i].insertText(clientName, Word.InsertLocation.replace);
}
clientName = "";
return context.sync().then(function () {
})
})
})
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다