Hi,
I want to replace bookmarks with “combo” in their name with a combobox.
Children of paragraghs such as combobox or paragraph cannot be inserted from a range.
How should I do it ?
thanks in advance
from OnlyOffice 7.1.1.25
Hi,
I want to replace bookmarks with “combo” in their name with a combobox.
Children of paragraghs such as combobox or paragraph cannot be inserted from a range.
How should I do it ?
thanks in advance
from OnlyOffice 7.1.1.25
Hello @David33
We’re checking the situation, I will update this thread as soon as possible.
By the way, your Document server (v.7.1) is outdated. We recommend to update installation timely.
in fact i am using 7.3.3.49
Hello,
After a lot of reading and trying I found this way :
oRange.Delete(); // this seem to put the current cursor (the current position in the doc) at the deleted range.
oDocument.InsertContent([oComboBoxForm]); // this insert new content at the current cursor
All the best,
We’re glad that you managed the situation. Please feel free to contact us if you face any issues.
Sorry, in fact some times it does not work and return " Uncaught TypeError: Cannot read property ‘ea’ of undefined " ?
It works if i put the contentControl in an InlineLvlSdt and in a created paragraph :
var oInlineLvlSdt1 = Api.CreateInlineLvlSdt();
oInlineLvlSdt1.AddText(“InlineLvlStd Label”);
var oParagraph = Api.CreateParagraph();
oParagraph.AddInlineLvlSdt(oInlineLvlSdt1);
oDocument.InsertContent([oParagraph]);
BUT, the insertion of a paragraph add also a space and a carriage return after the paragraph.
Is it possible to delete those spaces and the carriages returns and how ?
Or is it possible to replace the paragragh container by an appropriate inline container that can be inserted at the current range selection ?
Best.
Could you please share your test file and script itself (with detailed description of the issue) with us? We will check it out.
source doc is test.docx - Google Docs
php execute a docbuilder script to retrieve the textual content of the doc and parses all the variables, defined by a sequence of alphanum characters with at least one underscore.
$vars is :
Array
(
[ADR1_FIXE_CONSO] => adr1_fixe_conso
[ADR2_FIXE_CONSO] => adr2_fixe_conso
[ADR3_FIXE_CONSO] => adr3_fixe_conso
[ADR4_FIXE_CONSO] => adr4_fixe_conso
[ADRES1_EXPEDITION] => Adres1_expedition
[ADRES2_EXPEDITION] => Adres2_expedition
[ADRES3_EXPEDITION] => Adres3_expedition
[ADRES4_EXPEDITION] => Adres4_expedition
[CODE_CIV_EXPEDITION] => Code_Civ_expedition
[COMPL_EXPEDITION] => Compl_expedition
[DATE_IMPRESSION] => Date_impression
[NOM_EXPEDITION] => Nom_expedition
[NUM_DERNIER_PRODUIT_ACTIF] => Num_dernier_produit_actif
[NUM_ID] => Num_id
[V_A] => V_A
[V_B] => V_B
)
$docx="test.docx";
$out['docBuilder_script'] ='
builder.OpenFile("' . $docx . '");
var oDocument = Api.GetDocument() , aBookmarks = oDocument.GetAllBookmarksNames() ;
// remove all bookmarks
aBookmarks.forEach(function(element, index, Array) {
var oRange = oDocument.GetBookmarkRange(element);
oDocument.DeleteBookmark(element);
});
Api.Save();
';
if( is_array($vars)){
foreach ($vars as $k => $v) {
$v = trim($v);
$out['docBuilder_script'] .='
var aSearch = oDocument.Search("' . $v . '"), aSearchNb = aSearch.length;
for (var i = 0; i < aSearchNb ; i++ ){
// Bookmark name must be unique. So trying to suffix the item with its occurence number.
// BUT it displays 5 items of "V_A" and "V_B" instead of the 3 from the source.
// It seems like the initial search is refreshed after each replacement ???
var suffix = ""; if(aSearch.length>1) suffix = "__" + (i+ 1);
aSearch[i].AddBookmark("'.$v.'" + suffix );
aSearch[i].SetHighlight("yellow");
aSearch[i].Select();
var oI = Api.CreateInlineLvlSdt();
oI.AddText("' .$v . '"+suffix);
oI.SetAlias("' . $v . '"+suffix);
oI.SetPlaceholderText("' . $v . '"+suffix);
oI.SetTag("' .$v . '" );
oI.SetLock("sdtLocked");
var oP = Api.CreateParagraph();
oP.AddInlineLvlSdt(oI);
oP.SetSpacingBefore(0);
oP.SetSpacingAfter(0);
oP.SetHighlight("green");
// This insert oP at the current selection, the search item current selection via aSearch[i].Select();
// oDocument.InsertContent([oI]); throws error "Uncaught TypeError: Cannot read property ea of undefined"
// oDocument.InsertContent([oP]); works BUT a carriage return and a space is added after the block insertion.
oDocument.InsertContent([oP]);
Api.Save();
}';
}
}
$out['docBuilder_script'] .='
builder.SaveFile("docx", "' . $docx . '");
builder.CloseFile();';
result is
Questions are :
With the docbuilder script, how to replace the content of a range - via search() or GetAllBookmarksNames() results - with an inline content control or inline combobox, keeping the range’s original display styles ?
In fact I just wish I could do the same as what is done in the GUI :
How to avoid having additional variable generations? I mean I should only have V_A_1, V_A_2 and V_A_3. What is wrong ?
Ranges are highligtable. Thus, I can highlight in yellow all the variables of my document. But how do you remove all highlights from these vars? I tried to use bookmark containers but they need a unique id and when I try to name them with their occurrence number it becomes a mess?
Best