Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: change output file encoding in a google-script with DriveApp.createFile?


Let's explain the context of my request : I'm trying to output the content of a google spreadsheet in a .txt tabulated file, encoded in UTF-16, because I need this charset in a later task with this .txt file.

Actually, I've got the right output in the right folder and with the name I want ect ... but the charset is UTF-8 (i've check with an basic text editor).

The problem is I can't find any documentation about Charset Manipulation with google script. My only solution for now, is a basic manual charset manipulation in sublim text ...

Here's my code (translated from french).

Thank's for your replies !


function export() {
//sheet manipulation part
//Get the sheet and set data range i need
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getDataRange();
var values = sheet.getRange(2, 1, sheet.getLastRow()-1, sheet.getLastColumn()).getValues();
var text = (a) {return a.join('\t');}).join('\n');

//Path setting and export part
// Get sheet info, define path and create file
var id = SpreadsheetApp.getActiveSpreadsheet().getId();
var idString = id.toString();
var thisFile = DriveApp.getFileById(idString);
var parentFold = thisFile.getParents();
var folder =;
var theId = folder.getId();
var targetFolder = DriveApp.getFolderById(theId);
targetFolder.createFile('liste du ' + new Date() + '.txt', text, MimeType.PLAIN_TEXT);

Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered

This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: change output file encoding in a google-script with DriveApp.createFile?


Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription