Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9788

SOLVE - How to make a google script remove all content in a doc?

$
0
0

I sometimes need to temporarily write something in somewhere. I make a 'Temp' google doc, every times I use it I need to remove the content previously there. I want to make a google apps script to add a button to remove all content and format in doc. I try the following code:

function onOpen() {  DocumentApp.getUi()    .createMenu("Clear")    .addItem("Clear", "dialogs")    .addToUi();}function dialogs() {  var ui = DocumentApp.getUi();  var result = ui.alert("Please Confirm","Are you sure you want to clear the document?",    ui.ButtonSet.YES_NO);  if (result == ui.Button.YES) {DocumentApp.getActiveDocument().getBody().clear()}}

However it doesn't work. How to fix that?

The problem solved, when using .getBody().clear(), you need to make sure the last line of document is not in bollet point or other things. Add a blank line at the last paragraph, the code should work.


Viewing all articles
Browse latest Browse all 9788

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>