wolfolz.blogg.se

Insert text box google docs app
Insert text box google docs app








It is called a text box because it contains text and can be placed anywhere on the page without disturbing the other text, or breaking the flow of the text. A textbox is a drawn box that can be of any orientation and size and contains some text. When you use this script, please select a text and run the script.Today’s article is about how to insert a text box in google docs. When these points are reflected in the script, how about the following sample script? Sample script: In order to replace the selected text, it is required to use getSelection().I think that the reason for your current issue of TypeError: Cannot read properties of null (reading 'insertText') is due to this. In the case of var currentPosition = doc.getCursor() and currentPosition.insertText(generatedText.toString()), the selected text cannot be used.

insert text box google docs app

  • In your script, there are variables that are not used in the script.
  • But, your function completion(prompt) works fine.
  • Unfortunately, I cannot know your function completion(prompt).
  • You want to replace the selected text with generatedText = completion(prompt).
  • How can I replace the whole selection with a new text? Get the completion prompt from OpenAI API requestĬurrentPosition.insertText(generatedText.toString())

    insert text box google docs app insert text box google docs app

    Get the body of the document and the prompt for the OpenAI API requestĬonst prompt = doc.getSelection().getRangeElements().getElement().asText().getText() Get the active Google Docs document and the user-selected textĬonst doc = DocumentApp.getActiveDocument() Ĭonst userText = doc.getSelection().getRangeElements().getElement().asText().getText() I guess that this is due to the fact that selection is nothing to do with cursor position. TypeError: Cannot read properties of null (reading 'insertText') The script will work fine but I cannot update the current selection, as I get the following error I'm trying to write an app script to replace the current text selection with a new AI generated text, via menu item.










    Insert text box google docs app