My current data is hardcoded:
var geoData = new google.visualization.DataTable();
geoData.addColumn('string', 'City');
geoData.addColumn('string', 'Name');
geoData.addColumn('boolean', 'Yes/no');
var geoView = new google.visualization.DataView(geoData);
geoView.setColumns([0, 1]);
var query = new google.visualization.Query('http://spreadsheets.google.com/...')
Related
I have a Google script triggered on submission of a form. It creates a new doc based on a template with certain variables in-filled from answers in the form.
I also have a folder created on the form submission.
The trouble I am having is creating the newly created doc within the newly created folder. Looking for some help merging the two scripts that work on their own to acheive this.
Creating a folder on form submission:
function createChannelFolder() {
var ss = SpreadsheetApp.getActive();
var names = ss.getSheetByName("Completed Certifications");
var ChannelName = names.getRange(names.getLastRow(), 2).getValue();
var parentFolder=DriveApp.getFolderById("FOLDERID");
return newFolder=parentFolder.createFolder(ChannelName);
}
Creating a document on form submission
function autoFillGoogleDocFromForm(e) {
//e.values is an array of form values
var Timestamp = e.values[0];
var Channel = e.values[1];
var Name = e.values[2];;
var file = DriveApp.getFileById('FILEID');
var folder = DriveApp.getFolderById('FOLDERID')
var copy = file.makeCopy(Channel + ',' + Name, folder);
var newId = copy.getId();
var doc = DocumentApp.openById(newId);
var body = doc.getBody();
body.replaceText('{{Timestamp}}', Timestamp);
body.replaceText('{{Channel}}', Channel);
body.replaceText('{{Name}}', Name);
doc.saveAndClose();
}
Explanation:
You need to call createChannelFolder() inside
autoFillGoogleDocFromForm(e).
just return the folder object within createChannelFolder():
return parentFolder.createFolder(ChannelName);
Solution:
Here is autoFillGoogleDocFromForm(e):
function autoFillGoogleDocFromForm(e) {
//e.values is an array of form values
var Timestamp = e.values[0];
var Channel = e.values[1];
var Name = e.values[2];;
var file = DriveApp.getFileById('FILEID');
var folder = createChannelFolder(); // 1st modification point
var copy = file.makeCopy(Channel + ',' + Name, folder);
var newId = copy.getId();
var doc = DocumentApp.openById(newId);
var body = doc.getBody();
body.replaceText('{{Timestamp}}', Timestamp);
body.replaceText('{{Channel}}', Channel);
body.replaceText('{{Name}}', Name);
doc.saveAndClose();
}
and here is createChannelFolder():
function createChannelFolder() {
var ss = SpreadsheetApp.getActive();
var names = ss.getSheetByName("Completed Certifications");
var ChannelName = names.getRange(names.getLastRow(), 2).getValue();
var parentFolder=DriveApp.getFolderById("FOLDERID");
return parentFolder.createFolder(ChannelName); // 2nd modification point
}
I am trying to copy over all of the values and formats to a different spreadsheet, week by week, creating a new sheet within the workbook each time. This is for archival purposes. I have pieced together the following:
function ArchiveByWeek(){
var source = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('CRS Stats By Week')
var buildVersion = Browser.inputBox("What is the Weekend Ending Date?");
var sValues = source.getDataRange().getValues();
var sBG = source.getDataRange().getBackgrounds();
var sFC = source.getDataRange().getFontColors();
var sFF = source.getDataRange().getFontFamilies();
var sFL = source.getDataRange().getFontLines();
var sFFa = source.getDataRange().getFontFamilies();
var sFSz = source.getDataRange().getFontSizes();
var sFSt = source.getDataRange().getFontStyles();
var sFW = source.getDataRange().getFontWeights();
var sHA = source.getDataRange().getHorizontalAlignments();
var sVA = source.getDataRange().getVerticalAlignments();
var sNF = source.getDataRange().getNumberFormats();
var sWR = source.getDataRange().getWraps();
var destination = SpreadsheetApp.openById('1WVfJGDbdOewO2H-aMhQiek7sCOolK6xH7cSbfZ8KQgY');
var destinationSheet = destination.insertSheet(buildVersion, 1);
destinationSheet.getRange(1,1,sValues.length,sValues[0].length).setValues(sValues)
.setBackgrounds(sBG)
.setFontColors(sFC)
.setFontFamilies(sFF)
.setFontLines(sFL)
.setFontFamilies(sFFa)
.setFontSizes(sFSz)
.setFontStyles(sFSt)
.setFontWeights(sFW)
.setHorizontalAlignments(sHA)
.setVerticalAlignments(sVA)
.setNumberFormats(sNF)
.setWraps(sWR);
}
This seems to work fine, only some cells are not copied. For some reason, it is only cells that are summing other cells. Can't figure out why.
I found the following script, which worked perfectly, only I was unable to find a way to give each new sheet a unique name:
function copySheetValues(){
var source = SpreadsheetApp.getActiveSheet();
var sourcename = source.getSheetName();
var sValues = source.getDataRange().getValues();
var sBG = source.getDataRange().getBackgrounds();
var sFC = source.getDataRange().getFontColors();
var sFF = source.getDataRange().getFontFamilies();
var sFL = source.getDataRange().getFontLines();
var sFFa = source.getDataRange().getFontFamilies();
var sFSz = source.getDataRange().getFontSizes();
var sFSt = source.getDataRange().getFontStyles();
var sFW = source.getDataRange().getFontWeights();
var sHA = source.getDataRange().getHorizontalAlignments();
var sVA = source.getDataRange().getVerticalAlignments();
var sNF = source.getDataRange().getNumberFormats();
var sWR = source.getDataRange().getWraps();
var destination = SpreadsheetApp.openById('15ucPbZrIYXZAOCYVdpK6OA0oyQT1NcsmuiJmDRfdpHQ');
var destinationSheet = destination.insertSheet(sourcename, 0);
destinationSheet.getRange(1,1,sValues.length,sValues[0].length).setValues(sValues)
.setBackgrounds(sBG)
.setFontColors(sFC)
.setFontFamilies(sFF)
.setFontLines(sFL)
.setFontFamilies(sFFa)
.setFontSizes(sFSz)
.setFontStyles(sFSt)
.setFontWeights(sFW)
.setHorizontalAlignments(sHA)
.setVerticalAlignments(sVA)
.setNumberFormats(sNF)
.setWraps(sWR);
}
I was actually able to come up with a solution that I was satisfied with. This was able to paste all of the values, and formats exactly as they were on the sheet when viewing. It asks for a name of the new sheet, which was my intention:
function Archive() {
var source = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('SHEET NAME')
var sValues = source.getDataRange()
.getValues();
var weekEnding = Browser.inputBox("What is the Weekend Ending Date?");
var destination = SpreadsheetApp.openById('SHEET ID');
var copy = source.copyTo(destination)
.setName(weekEnding)
copy.getRange(1, 1, sValues.length, sValues[0].length)
.setValues(sValues); // overwrite all formulas that the copyTo preserved
I have a spreadsheet and I want to take a range of data and manipulate it to look differently. I am thinking that I will have set-up multiple loops
1 - To get the main student data (A2:I26) and add it the new sheet.
2- Then loop the range of Test Headings, ex. A,B,C,etc and add those behind the student details.
3- Then another loop to grab the range of scores under each test heading an add them after the test name.
I started writing a script that gets the sheet ranges etc, but I am not sure how to add the loops. FYI - Some Sheets I have to convert have more Headings of scores than Just A,B,C...Some Sheets I have to work with might just have A scores, some might have scores for A-E etc.
Thanks for any help you can give.
Brandon
***THE SHEET IMAGES AND SIMPLE SCRIPT ARE BELOW
I am looking to take the sheet that looks like this:
And use a script to make it look like this:
function dataReport() {
var thisSS = SpreadsheetApp.getActiveSpreadsheet(),
classData = thisSS.getSheets()[3], //The Sheet with the original data
dataLastRow = classData.getLastRow(),
Avals = classData.getRange("A1:A").getValues(),
Alast = Avals.filter(String).length,
classDataRange = classData.getRange(3, 1,Alast, 9),
dataArray = classDataRange.getValues();
var testNames = classData.getRange(2, 10, 1, classData.getLastColumn()-9),
tnArray = testNames.getValues();
var reportSheet = thisSS.getSheets()[4]; //The sheet to insert the new data
var reportSheetNewRow = reportSheet.getLastRow() +1;
var newDataRange = reportSheet.getRange(reportSheet.getLastRow()+1, 1,Alast, 9);
newDataRange.setValues(dataArray);
}
It seems I've found an answer, so I figured I'd post it. The loops to re-arrange the sheet accordingly would look like this. I'm sure there is a faster way, but this is what I came up with.
function dataReport() {
var thisSS = SpreadsheetApp.getActiveSpreadsheet(),
classData = thisSS.getSheets()[3],
dataLastRow = classData.getLastRow(),
Avals = classData.getRange("A1:A").getValues(),
Alast = Avals.filter(String).length,
classDataRange = classData.getRange(3, 1,Alast, 9),
standardCols = classData.getRange("J2:2").getValues(),
arrayOfStandards = standardCols.join().split(","),
filtArr = arrayOfStandards.filter(Boolean);
var dataArray = classDataRange.getValues();
for(var i=0; i < filtArr.length; i++){
var reportSheet = thisSS.getSheets()[4];
var reportSheetNewRow = reportSheet.getLastRow() +1;
var newDataRange = reportSheet.getRange(reportSheetNewRow, 1,Alast, 9);
var avgValues = classData.getRange(3, 10+i, Alast, 1);
var avgArray = avgValues.getValues();
var newAvgRange = reportSheet.getRange(reportSheetNewRow, 11,Alast, 1);
newDataRange.setValues(dataArray);
newAvgRange.setValues(avgArray);
for (var j=0, x = dataArray.length; j<x; j++){
reportSheet.getRange(reportSheetNewRow + j, 10).setValue(filtArr[i]);
}
}
}
I am new to Google Org Chart.
Having a tough time selecting some default nodes in my chart by code.
Like in this case I want "jordan" to be selected automatically.
Note: Node selection is dynamic
Thanks in advance.
At last done by myself.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Group');
data.addColumn('string', 'Parent');
data.addColumn('string', 'ToolTip');
var response = [
['Mark', '', 'Mark'],
['John', 'Mark', 'John'],
['Mary', 'Mark', 'Mary'],
['Jordan', 'Mary', 'Jordan'],
['Eli', 'Mary', 'Eli'],
['Ivan', 'Mary', 'Ivan'],
['Sarah', 'John', 'Sarah'],
['Mike', 'John', 'Mike']
];
data.addRows(response);
var chart = new google.visualization.OrgChart(document.getElementById('grouporgdiv'));
chart.draw(data, {allowHtml:true});
var selectedArray = new Array();
var counter = 0;
var commaSeperatedDefaultValues = "Jordan";
var defaultValuesArray = commaSeperatedDefaultValues.split(",");
for(i=0;i<response.length;i++) {
chart.setSelection([{row: i}]);
var temp = chart.getSelection()[0];
var a = defaultValuesArray.indexOf(data.getValue(temp.row, 2));
if(a != -1)
selectedArray[counter++] = temp;
}
chart.setSelection(selectedArray);
I have a script that captures information from a panel. Once the info has been entered, user clicks a Submit button and the data entered is stored in a spreadsheet that will later be used to replace some fields of a template that I have on a cell on that spreadsheet. This process is very time consuming, like around a minute to perform all this. What I was wondering is if is possible that instead of storing the data in a cell on the spreadsheet if I can use the parameters info, and replace it on the template I have. Any ideas on how to do this?
function a(e) {
var doc = SpreadsheetApp.getActiveSpreadsheet();
var timecell = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Templates").getRange("A2");
var timebval = timecell.setValue(e.parameter.Times);
var t1 = timecell.getValue();
var mincell = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Templates").getRange("A3");
var minbval = mincell.setValue(e.parameter.Minutes);
var t2 = mincell.getValue();
var namecell = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Templates").getRange("A4");
var nabval = namecell.setValue(e.parameter.Name);
var t3 = namecell.getValue();
var email = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Templates").getRange("A5");
var emaval = email.setValue(e.parameter.email);
var t4 = email.getValue();
var address = "albdominguez25#gmail.com";
var advancedArgs = {bcc:t4};
var emailSubject = "Test";
var emailTemplate =SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Templates").getRange("A1").getValue() ;
emailTemplate = emailTemplate.replace("TIME",t1).replace("MIN",t2).replace("EXP",t3);
MailApp.sendEmail(address, emailSubject, emailTemplate, advancedArgs);
Browser.msgBox("Your Email has been sent!");
Instead of storing something to a spreadsheet and reading back from it for each value, just directly use the value in the replace method as shown below.
function a(e) {
var address = e.parameter.email;
var advancedArgs = {bcc:t4};
var emailSubject = "Test";
var emailTemplate = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Templates").getRange("A1").getValue() ;
emailTemplate = emailTemplate.replace("TIME", e.parameter.Times).replace("MIN", e.parameter.Minutes).replace("EXP", e.parameter.Name);
MailApp.sendEmail(address, emailSubject, emailTemplate, advancedArgs);
Browser.msgBox("Your Email has been sent!");
}
If you must store these values in your spreadsheet also for later reference, it is faster to do one setValues instead of calling setValue several times. After you use the parameter info to send the email, just call this to set all the values at once:
var range = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Templates").getRange("A2:A5");
range.setValues([[e.parameter.Times], [e.parameter.Minutes], [e.parameter.Name], [e.parameter.email]]);