2015-03-02 78 views
1

是否可以使用Google脚本从Google工作表创建Excel格式文件,以便它可以作为附件添加到电子邮件中?通过谷歌脚本以ms Excel格式创建附件通过Google脚本

我有一个代码,它需要某些名称(例如A,C,F)的列,并将它们变成一个新表(在createCustomStatusTable()函数上)。 https://docs.google.com/spreadsheets/d/1fZ0JMYjoIrfPIxFBVgDNU0x5X0ll201ZCU-lcaTwwcI/edit?usp=sharing

var expected = ['A','C','F']; 
var newSpreadSheet = SpreadsheetApp.getActiveSheet(); 
var tableLastRow = newSpreadSheet.getLastRow(); 
var tablelastColumn = newSpreadSheet.getLastColumn(); 
var values = newSpreadSheet.getRange(1, 1, tableLastRow, tablelastColumn).getValues(); 
var rangeToCopy = []; 

function in_array(value, array) 
{ 
    for(var i = 0; i < array.length; i++) 
    { 
     if(array[i] == value) return true; 
    } 
    return false;; 
}; 
function columnsCount() { 
    var count = 1; 
    for (var i = 0; i < SpreadsheetApp.getActiveSheet().getLastColumn(); i++) { 
    if (in_array(values[0][i],expected)) 
     count++; 
    } 
    return count; 
}; 
function returnRange() { 
    for (var i = 1; i < SpreadsheetApp.getActiveSheet().getLastColumn()+1; i++) { 
    if (in_array(values[0][i-1],expected)) { 
     rangeToCopy.push(newSpreadSheet.getRange(1, i, newSpreadSheet.getMaxRows())); 
    };  
    }; 
    return rangeToCopy; 
}; 

function createCustomStatusTable() { 
var targetSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Target'); 
for (var i = 1; i < columnsCount(); i++) { 
     returnRange()[i-1].copyTo(targetSheet.getRange(1,i)); 
    }; 
}; 

预先感谢您的任何帮助

回答

0

您可以创建DriveApp一个EXCEL文件类型:

DriveApp Excel Type

的问题是,该content必须是字符串。而且我还没有测试过这种工作方式。

我知道这并不能回答你的问题。希望有人知道如何从Google表创建一个EXCEL文件。

+0

我需要这样的[链接](https://gist.github.com/ixhd/3660885),但以Excel格式.xlsx。可能吗? – 2015-03-03 12:22:28