我有一张表格,其中包含有关用户的一些信息,例如:
姓名,时间,地点 彼得,15.01.15,法兰克福 迈克尔,18.02.15,法兰克福 彼得,17.02.15,巴黎 迈克尔,17.02.15,巴黎
我想要为每个独特用户创建一个新工作表并对新工作表进行排序。这可能与GAS有关吗?它应该是这样的:
/ 新表 / 姓名,时间,地点 彼得,15.01.15,法兰克福 彼得,17.02.15,巴黎 / 新表 / 姓名,时间,地点 迈克尔,17.02.15,巴黎 迈克尔,18.02.15,法兰克福
感谢。 编辑:
function getall(){
var ss = SpreadsheetApp.getActiveSpreadsheet(),
sourceSheet = ss.getSheetByName('Source'),
newSheet = ss.insertSheet('newSheet'),
sourceRange = sourceSheet.getDataRange(),
sourceRows = sourceRange.getValues();
newSheet.appendRow(sourceRows[0]);
var i;
for (i = 1; i < sourceRows.length; i += 1) {
newSheet.appendRow(sourceRows[i]);
}
Browser.msgBox("New Sheet Added!");
}
编辑2:
var ss = SpreadsheetApp.getActiveSpreadsheet(),
sourceRange = ss.getDataRange(),
sourceRows = sourceRange.getValues();
var users = {},
colWithTheUsersNames = 6,
currSheet;
for( var lin = 1; lin < sourceRows.length; lin++ ){
if( !users[ sourceRows[lin][colWithTheUsersNames] ] ) sourceRows[lin] [colWithTheUsersNames] = [];
users[ sourceRows[lin][colWithTheUsersNames] ].push( sourceRows[lin] [colWithTheUsersNames] );
}
for( var usr in users ){
currSheet = ss.insertSheet( usr );
currSheet.getRange(1,1, users[usr].length, users[usr][0].length ).setValues(users[usr]);
}
编辑3:
var ss = SpreadsheetApp.getActiveSpreadsheet(),
sourceRange = ss.getDataRange(),
sourceRows = sourceRange.getValues(),
users = {},
colWithTheUsersNames = 6,
currSheet;
for( var lin = 1; lin < sourceRows.length; lin++ ){
if( users[ sourceRows[lin][colWithTheUsersNames] ] ) sourceRows[lin][colWithTheUsersNames] = [];
for(var column = 0; column < sourceRows.length; column++){
if("undefined" != typeof users[sourceRows[lin][colWithTheUsersNames]]) {
if("undefined" != typeof sourceRows[lin][column]){
users[sourceRows[lin][colWithTheUsersNames] ].push(sourceRows[lin][column]);
}
}
else {
users[sourceRows[lin][colWithTheUsersNames] ] = new Array();
if("undefined" != typeof sourceRows[lin][column]){
users[sourceRows[lin][colWithTheUsersNames] ].push(sourceRows[lin][column]);
}
}
}
}
// users[ sourceRows[lin][colWithTheUsersNames] ].push( sourceRows[lin][column]);
var i = 0;
for( var usr in users ){
currSheet = ss.insertSheet( usr );
Logger.log(typeof users[usr]);
currSheet.getRange(1,1, users[usr].length, users[usr].length ).setValues(users[usr]);
}
编辑4:
function getallEmployer(){
var ss = SpreadsheetApp.getActiveSpreadsheet(),
sourceRange = ss.getDataRange(),
sourceValue = sourceRange.getValues(),
sourceRows = sourceRange.getNumRows(),
users = {},
colWithTheUsersNames = 7,
currSheet;
for( var lin = 1; lin < sourceRows; lin++ ){
if( users[ !sourceValue[lin][colWithTheUsersNames] ] ) sourceValue[lin][colWithTheUsersNames] = [];
//for(var column = 0; column < sourceValue[lin].getNumColumns; column++){
if("undefined" != typeof users[sourceValue[lin][colWithTheUsersNames]]) {
if("undefined" != typeof sourceValue[lin]){
users[sourceValue[lin][colWithTheUsersNames] ].push(sourceValue[lin]);
}
}
else {
users[sourceValue[lin][colWithTheUsersNames] ] = new Array();
if("undefined" != typeof sourceValue[lin]){
users[sourceValue[lin][colWithTheUsersNames] ].push(sourceValue[lin]);
}
// }
}
}
// users[ sourceRows[lin][colWithTheUsersNames] ].push( sourceRows[lin][column]);
var i = 0;
for( var usr in users ){
currSheet = ss.insertSheet( usr );
var range = currSheet.getRange("A1:D1");
var parameters = [["Date","Name","Project Category", "Time","Nicht verrechenbar","Bemerkung"]];
range.setValues(parameters);
Logger.log(typeof users[usr]);
currSheet.getRange(2,1, users[usr].length, users[usr][0].length ).setValues(users[usr]);
}
}