How to load data from a .htm file with google apps sciript - html

I set up a automated job via SAP (SM36) where I recieve a report as an attachment on a regular basis via e-mail (GMail). This is working fine but I just received an .htm file from SAP so that I need to transfer the data into a google or excel sheet. Unfortunately, it is not possible to receive the file directly as a .xlsx file.
I know how I can get the .htm file out of gmail into my drive via GApps Script. The next step is to get the data out of this file into a google spreadsheet. I wasn´t able to figure out how I can do this so I ask you to help me with this regard.
How can I get the data out of the report (.htm file) into a google spreadsheet or directly into a excel sheet via Google Apps Script?
Many thanks in advance!
Best regards,

search(query)
getMessages()
getAttachments()
getDataAsString()
openById(id)
setValues(values)

Related

Offline download of Google Spreadsheet that saves Google script code as well

What's an efficient way of making an offline backup of a Google spreadsheet so that it includes its Google script files? It seems that if I use the Download as Microsoft Excel File feature, the downloaded xlsx file does not include any Google script that is part of the spreadsheet.
I saw a post about a command line tool called "Clasp" by Google that can be used but I was hoping to use something that is not so arcane.

How to access and extract data in App Script that is not bound to the code

I am working on a script that is standalone. It collects its baseline data from a google sheet bound to a form. In the form submission, excel documents are uploaded. While I can access the link for the excel document(google downloads the excel into your drive upon submission and inserts the drive link into the google response sheet), I am having difficulty looking into and extracting anything (exact cell values, ranges, indexes, etc) from the excel doc.
I have tried using various functions from the sheets and spreadsheets classes and continue to get errors. Some suggestions I've found say the excel document needs to be converted into a google sheet before the app script can access it, or that app script won't allow you to work with such a document if it is not bound to your script (since that allows you to activate it)(I can't bind the excel doc because it changes upon every new submission of the form).
Has anyone ever compiled a similar code and figured out how to access an unbound, non-google doc?
Let me know if you need error codes or script snippets. I just wasn't sure if this was a syntax problem or a google suite trick spot that needed extra code that I probably haven't found cause I'm new to this platform.
From the question
Has anyone ever compiled a similar code and figured out how to access an unbound, non-google doc?
Scripts in Google Apps Script aren't "compiled" by the script writer in the sense that it's done when developing something in other platforms.
To get data from a file hosted in Google Drive, first the script should get that file by using the Drive Service (Class DriveApp) or the Drive Advanced Service.
The next part depends pretty much on the Excel file format. If it's an xlsx file, then usually the most convenient is to convert the file into an Google spreadsheet as this will make possible to use the Spreadsheet Service (Class SpreadsheetApp) to read the data from it.
If you don't want to convert it to a Google spreadsheet file, or it can't be converted the the "basic" means because it's using an incompatible format (like a xls file format), then you will need to use an library or an external service to parse the Excel file content.
function getalldataonsheet() {
const ss=SpreadsheetApp.openById('ssid');//you provide id
const sh=ss.getSheetByName('sheetname');//you provide sheet namme
const rg=sh.getDataRange();
const vs=rg.getValues();//2d array
return vs;//this return 2d array
}
There are restrictions for passing parameters in client to server communication

can you open a excel file directly with google sheets api

how can I open a excel file directly with google sheets api
Not to my knowledge, however, using the Drive API you can upload and convert an Excel file to Sheets format automatically. This could then be used by the Sheets API. This may or may not work as a substitute in your use case.
Well you can read a .xlsx file as a binary blob from Google Apps Script API. So if you want to read the xlsx formatted file and do all the work of interpreting it yourself, then sure you can. But that's essentially writing the entire MS Excel interpreter in Google Script.

is it possible to download GMail attachment to local folder?

i want to download attachment from gmail and save it to local folder using google script. i did some research about this and i could't find any solution.
so far, i managed to save gmail's attachment to google drive only.
var attachmentBlob = attachment[0].copyBlob();
var file = DriveApp.createFile(attachmentBlob);
folder.addFile(file);
or, is it possible to create a google script to auto download file from google drive?
need some advice.
As #Sujay already mentioned you cannot download a file to a local folder using Google AppScript because GAS runs server-side.
You have already taken a good step with the code to save the attachment as a file to your Google drive.
To answer your sub-question 'is it possible to create a google script to auto download file from google drive?', you do not need a script to do that, that is what the Google Drive Desktop App (https://www.google.com.ng/drive/download/) does exactly.
It syncs all the files you add to your drive to your local-pc. You can also edit Google Drive preferences to sync select folders only, in your case that might be the drive folder referenced in your folder variable.
GAS runs on the server side, and only has access to Google's internal architecture. To save locally it'll need to create some kind of a blob and trigger a download within your browser. not sure if you can do that.

Google apps script save google spreadsheet to excel version and load it from add-on

Hi I have an idea about file management between GAS and my BDserver. How so? Well, I'd like to have predesigned spreadsheet and save them somehow in my bd. Then users've installed my add-on can load that predesigned spreadsheet on his/her current spreadsheet. PD: Besides the user could save custom "predesigned spreadsheets" for helping to grow the app. How can I save a spreadsheet (Google Drive Spreadsheet) in my server and later call that "file" and load it in a empty spreadsheet? xml? json? export like excel file .xls??. I appreciate your suggestions.
You may find helpful information in Google Apps Script regarding the things that you can do with Google Apps like Docs, Sheets and Forms. You can also find links from the documentation which could help if you've developed a script for Google Sheets and want to share it with the world. App Script lets you publish your script as an add-on so others can install it from the add-on store.
In addition to that, to save your spreadsheet in your own database, you need to connect to it through Apps Script's JDBC service. First, you need to ensure that your database accepts connections from any of Apps Script's IP addresses as detailed in JDBC - Setup for other databases.