0

I am writing a script that is supposed to fill variables on a Google Slides document using information in cells on a Google Sheets document.

I have that part of the script working, but I would like to do some error checking before hand to check that all of the required columns exist, and there aren't any missing / not needed.

Is there any way, using Google Apps Script, to search through a Google Slides document without using replaceAllText. All I want to do is to find places where the variables that are necessary exist, and Logger the ones that are extraneous.

Joe Hays
  • 35
  • 5
  • I'm really sorry for my poor English skill. Can I ask you about the situation what you want? About ``All I want to do is to find places where the variables that are necessary exist, and Logger the ones that are extraneous.``, I couldn't understand ``places`` and ``Logger the ones that are extraneous``. For example, ``places`` is the page number or coordinate on the page? Can you show more information? – Tanaike Aug 01 '18 at 23:50
  • When I said places, I meant all of the times/locations in the Google Slides document that text matching my search function exists ie: searching for {{Name}}, all the times that {{Name}} appears in the Google Slides document. As for the Logger I was simply referring to the function `Logger.log(data);` which writes the information inside the () to a log file – Joe Hays Aug 02 '18 at 12:31
  • Thank you for your response. For example, you want to retrieve the number of ``{{Name}}``. I could understand that Logger is ``Logger.log(data)``. Is my understanding correct? And what is ``the ones that are extraneous``? – Tanaike Aug 02 '18 at 23:38
  • Your understanding is correct, by `the ones that are extraneous` I mean to say that I want to put into the logs every time there is something between {{}} that doesn't match on the spreadsheet ie: User has a spreadsheet with the cells {{Name}} and {{Number}}, but on the slides document it has {{Name}}, {{Number}}, {{Location}}. In this example I would want to log the {{Location}} from the slides document so that a cell with {{Location}} can be added to the Sheets document – Joe Hays Aug 03 '18 at 12:30
  • Although I'm not sure about your latest script, if my understanding for what you want is correct, you can achieve it using [``find(pattern)``](https://developers.google.com/apps-script/reference/slides/text-range#find(String)) of Class TextRange by scanning cells in a table. About putting values to Spreadsheet, you can do it using [``setValue()``](https://developers.google.com/apps-script/reference/spreadsheet/range#setValue(Object)) and [``setValues()``](https://developers.google.com/apps-script/reference/spreadsheet/range#setvaluesvalues) of Class Range. – Tanaike Aug 03 '18 at 23:38
  • I was able to find that resolution myself, but the problem with it is that the TextRange class is limited to operations inside a shape, or table cell, but I need to scan the whole Slides document, not just one small piece of it – Joe Hays Aug 06 '18 at 12:37
  • 1
    I'm really sorry I misunderstand your situation. From your comment, I had thought that you want to find text values from cells of table. When you also want to find text values from other objects, you can retrieve it as follows. 1. Retrieve elements in a page using getPageElements(). 2. Retrieve text values from each object. You can see the document at [here](https://developers.google.com/apps-script/reference/slides/page) and [here](https://developers.google.com/apps-script/reference/slides/page-element). – Tanaike Aug 06 '18 at 22:19
  • So, I've figured out how to use `getPageElement` and am able to log the page elements, but I still can't figure out how to get search through the text in those elements. Could you please give me an example of what the code should look like? – Joe Hays Aug 07 '18 at 14:59
  • Can you provide your latest script? I think that it will help to think of your modification points. – Tanaike Aug 07 '18 at 22:07
  • I've just been trying to get it to work in the Slides document right now using a test function, I haven't even attempted connecting it to the Sheets document, I can figure that out on my own. Here's the test function, though I doubt it will help you. `function Test(){ var slide = SlidesApp.getActivePresentation().getSlides()[0]; var GetElements = slide.getPageElements(); Logger.log(GetElements); }` – Joe Hays Aug 08 '18 at 12:48
  • Thank you for replying. ``GetElements`` is an array. You can retrieve text values from the array by for loop. For example, when you want to retrieve a value from SHAPE, you can use ``GetElements[0].asShape().getText().asString()``. You can see the document at [here](https://developers.google.com/apps-script/reference/slides/page-element). By the way, could you please update your question using your script? Because it is difficult for other users to see the script in comments. – Tanaike Aug 08 '18 at 21:55
  • And can you provide a sample slides including the sample input and output you want to expect? It will help users think of your solution. – Tanaike Aug 08 '18 at 22:49
  • @Tanaike: Hi. Thank you for your patient reply, as always. I have the same problem with the OP. Basically, what the OP (and myself) wanted is something similar to this function in Document https://developers.google.com/apps-script/reference/document/body#findtextsearchpattern. – 0xh8h Oct 22 '19 at 09:10
  • @Hoang Trinh Thank you for replying. Unfortunately, I couldn't understand about your question. I have to apologize for my poor English skill. If you want to resolve your issue, can you post it as new question by including the information? By this, it will help users including me think of the solution. – Tanaike Oct 22 '19 at 12:35

0 Answers0