Home > OS >  How to send data to Google Sheets as base64 string using Apps Script
How to send data to Google Sheets as base64 string using Apps Script

Time:08-02

  • I am new to Apps Script and I am trying to implement where I am taking an input through Google Sheets by using Apps Script. The user gets prompted with a HTML form through which the user uploads a PDF file.
  • The file is further saved in a google drive and further used for processing the PDF.
  • One way of importing csv file into Google Sheets is uploading the output to the Google Drive and then importing the CSV to a new sheets. I am able to achieve this.
  • My question is can I cut the middle-ware of Google Drive and directly give base-64 string as an input maybe by using callback url to the Google Sheets and the output is generated?

CodePudding user response:

Something like this?

function myFunction() {
  var csv_string = 'aa,bb,cc\n11,22,33'; // original csv string

  var base64data = Utilities.base64Encode(csv_string); // encoded string
  console.log(base64data);
  
  var decoded = Utilities.base64Decode(base64data); // decoded string
  console.log(decoded);
  
  var string = Utilities.newBlob(decoded).getDataAsString(); // csv string
  console.log({string});

  var array = Utilities.parseCsv(string) // 2d array
  console.log(array)
}

Reference: enter image description here

Here is my sheet.

  • Related