Googleのスプレッドシートを使用して、何かのための数値データを試作しています。基本的にサブセットをテキストファイルにエクスポートする方法はありますか?効果的には、別のプロジェクトのビルドに直接含めることができるファイルをエクスポートすることを目指しています。Googleスプレッドシートスクリプトからファイルを生成できますか?
ダウンロードするテキストファイルを生成する方法はありますか?
Googleのスプレッドシートを使用して、何かのための数値データを試作しています。基本的にサブセットをテキストファイルにエクスポートする方法はありますか?効果的には、別のプロジェクトのビルドに直接含めることができるファイルをエクスポートすることを目指しています。Googleスプレッドシートスクリプトからファイルを生成できますか?
ダウンロードするテキストファイルを生成する方法はありますか?
Google Appsアカウントをお持ちの場合は、DocsList.createFile()を使用してテキストファイルを作成し、ドキュメントリストに保存することができます。
このセクションの第3部では、スプレッドシートの選択範囲を文書リストのファイルとしてCSV形式で保存する方法を示しています。これはかなり簡単に変更して別の形式で保存することができます。
Googleスプレッドシートの一部の列に私のプロジェクトのテキストがあります。 私はこれをscript tutorial from Googleとし、特定の範囲(以下の例ではD4:D)のみを選択するように修正しました。
ドライブのルートフォルダにCSVファイルを生成します。それはまだファイルをダウンロードしない - 私は今それに取り組んでいます。
希望すると助かります! DocsListサービスはもはや機能しhttps://developers.google.com/apps-script/articles/docslist_tutorial#section3 */
/* The code below is a modification from this tutorial: https://developers.google.com/apps-script/articles/docslist_tutorial#section3 */
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var csvMenuEntries = [{name: "Save as CSV file", functionName: "saveAsCSV"}];
ss.addMenu("CSV", csvMenuEntries);
}
function saveAsCSV() {
// Name the file
fileName = "quests.csv";
// Convert the range data to CSV format
var csvFile = convertRangeToCsvFile_(fileName);
// Create a file in the root of my Drive with the given name and the CSV data
DriveApp.createFile(fileName, csvFile);
}
function convertRangeToCsvFile_(csvFileName) {
// Get from the spreadsheet the range to be exported
var rangeToExport = SpreadsheetApp.getActiveSpreadsheet().getRange("D4:D");
try {
var dataToExport = rangeToExport.getValues();
var csvFile = undefined;
// Loop through the data in the range and build a string with the CSV data
if (dataToExport.length > 1) {
var csv = "";
for (var row = 0; row < dataToExport.length; row++) {
for (var col = 0; col < dataToExport[row].length; col++) {
if (dataToExport[row][col].toString().indexOf(",") != -1) {
//dataToExport[row][col] = "\"" + dataToExport[row][col] + "\"";
dataToExport[row][col] = dataToExport[row][col];
}
}
// Join each row's columns
// Add a carriage return to end of each row, except for the last one
if (row < dataToExport.length-1) {
csv += dataToExport[row].join(",") + "\r\n";
}
else {
csv += dataToExport[row];
}
}
csvFile = csv;
}
return csvFile;
}
catch(err) {
Logger.log(err);
Browser.msgBox(err);
}
}
:
/*以下のコードは、このチュートリアルからの変更はありませんhttps://developers.google.com/apps -script/sunset –