Write data from kmz on sheet with Google Apps Script

user13157078

I'm very new in Google Apps Script. I have to read data from multiple kmz (placemarks and desccriptions mainly). So far I have managed to read and parse it with XmlService. What is the best way to transfer data to the spreadsheet?

  var kmzFile = DriveApp.getFileById('<ID>').getBlob();
  var unzipBlobs = Utilities.unzip (kmzFile.setContentType('application/zip'));
  var xml = unzipBlobs[0].getDataAsString()
  var document = XmlService.parse(xml)
  var root = document.getRootElement();
  var nameSpace = root.getNamespace()
  var folderRoot = root.getChild('Document', nameSpace).getChild('Folder', nameSpace)
  var folders = folderRoot.getChildren('Folder', nameSpace)
ziganotschka

How to parse the kmz depends on the structure of the specific document, but assuming your data of interest is contained in folders:

Here is a sample of how to insert the retrieved kmz data into a new sheet of a given spreadsheet:

var ss = SpreadsheetApp.openById("PASTE THE SPREADSHEET ID HERE");
var newSheet = ss.insertSheet();
var values = [];
if(folders.length!=0){
  for (var i = 0; i< folders.length; i++){
      values[i]=[];
      values[i].push(folders[i]);
    }
  newSheet.getRange(1,1,values.length, values[0].length).setValues(values);
  }

Basically, you iterate through all folders and dynamically create a value range of the size of the data and then assign it to a range in a sheet.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I write the data in Firestore to Google Sheet with app script?

Create an in-cell drop-down (Google Sheet Data Validation) from a CSV list with Apps Script

Google Apps Script: Google Sheet Grouping

How to get the specific range of row data from google sheet through apps script

Google Sheet Apps Script: How do I edit the Apps Script below to only copy over data from Column A to L and P to S?

Pivot or Transpose data in a google sheet using apps script

Apps Script to update Timestamp when data is inserted automatically in google sheet

Google Apps Script -> write Text from Document to Sheet

Wrap text using input from Google Sheet (Google Apps Script)

Google apps script - Importing sheet values from another sheet

Google Script - get data from Gmail into Sheet

Applying Google Apps Script for Dynamic Data Validation to Existing Sheet

Google Sheet data Apps Script not showing values in WebApps

Need to Query Google Sheet for specific data from Google Apps Script

How to Add 'Data List' in Google Sheet Apps Script that Populates Data from from Google Sheet with Bootstrap and HTML5

google apps script - write data in next empty row

Google Apps Script - How to send HTML email from Sheet?

copy data matches from one sheet to another within a specific row range Google apps script

A more efficient way of transferring bulk amount of rows from sheet to sheet - Google Apps Script

How to match and import data from other sheet by using apps script?

Apps Script update data from one cell in a sheet to a cell in a different sheet

How to print the data of an array into a Google sheet with Google Apps Script

Apps Script: Fill template with rows of data from Google Sheet. HOW to make it more dynamic?

Scrape data from website using Google apps script and paste to Google sheet

Add/Update Google Sheet Row Data Comparing Values from HTML Form Using Google Apps Script - Trying to Find Match on Sheet & Update Selected Row Data

Compare data in source sheet with target sheet and copy missing rows to target sheet with Google Apps Script

Google Apps Script Copying certain cells from a sheet into another sheet without repeating data

How to Preserve Sheet Formats and Translate? ( Google Apps Script, google sheet )

How to open a sidebar with data from a sheet, passing a variable from server to client-side in Google Apps Script?