You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need to insert some text in a table cell and move the cursor to the next cell. How can I check if the cursor is inside a table cell? How can I move the cursor to the next cell?
Inserting the text is done via the following code:
exportasyncfunctioninsertCurrentDate(){try{awaitWord.run(async(context)=>{// Get the current selectionvarselection=context.document.getSelection();// Insert the current date at the cursor positionvarcurrentDate=newDate().toLocaleDateString();selection.insertText(currentDate,Word.InsertLocation.end);awaitcontext.sync();});}catch(error){console.log("Error: "+error);}}
Although I said Word.InsertLocation.end the cursor is still where it was before and not moved after the inserted text.
I also have a working VSTO-AddIn where I used the following code, but was not able to find the corresponding JavaScript APIs.
privatevoidInsertCurrentDate(){try{
Microsoft.Office.Interop.Word.Document activeDoc= Globals.ThisAddIn.Application.ActiveDocument;if(activeDoc!=null){
Microsoft.Office.Interop.Word.Selection selection= Globals.ThisAddIn.Application.Selection;// Check if we are in a table cellif(selection.Information[Microsoft.Office.Interop.Word.WdInformation.wdWithInTable]){stringdateString= DateTime.Now.ToString("d");// Format the date as needed
selection.TypeText(dateString+"");// Insert the date and a space// Now, attempt to move to the next cellobjectunit= Microsoft.Office.Interop.Word.WdUnits.wdCell;objectextend=1;// Move one cell to the right
selection.MoveRight(ref unit,ref extend);}else{
selection.TypeText(DateTime.Now.ToString("d"));// Just insert the date if not in a table}}}catch(Exceptionex){
System.Diagnostics.Debug.WriteLine("Error inserting date: "+ ex.Message);}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I need to insert some text in a table cell and move the cursor to the next cell.
How can I check if the cursor is inside a table cell?
How can I move the cursor to the next cell?
Inserting the text is done via the following code:
Although I said
Word.InsertLocation.end
the cursor is still where it was before and not moved after the inserted text.I also have a working VSTO-AddIn where I used the following code, but was not able to find the corresponding JavaScript APIs.
Beta Was this translation helpful? Give feedback.
All reactions