मेरे पास Google स्प्रेडशीट के कुछ कॉलम में मेरे प्रोजेक्ट के ग्रंथ हैं। मैंने यह script tutorial from Google लिया और इसे केवल एक विशिष्ट श्रेणी (नीचे दिए गए उदाहरण में डी 4: डी) चुनने के लिए संशोधित किया।
यह आपके ड्राइव रूट फ़ोल्डर में एक CSV फ़ाइल उत्पन्न करता है। यह अभी भी फ़ाइल डाउनलोड नहीं करता है - मैं अब उस पर काम कर रहा हूं।
उम्मीद है कि यह मदद करता है!
/* नीचे दिए गए कोड इस ट्यूटोरियल से एक संशोधन है: 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);
}
}
स्रोत
2016-07-22 15:06:56
DocsList सेवा अब कार्यात्मक है: https://developers.google.com/apps -script/सूर्यास्त –