I am attempting to create a additional menu option that allow me to automatically delete all rows that contain the text "Complete" in Column D. The script I have runs and finishes with no errors but does not delete the rows. I tried to find help on line and tweaked the code but same result
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
var rowsDeleted = 'Complete';
for (var i = 'Complete'; i <= numRows - 1; i++) {
var row = values[i];
if (row[2] == 'Complete' || row[2] == '') {
sheet.deleteRow((parseInt(i)+1) - rowsDeleted);
rowsDeleted++;
}
}
};
function onOpen() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var entries = [{
name : "Delete Rows where column shows Complete Text",
functionName : "readRows"
}];
sheet.addMenu("Script Center Menu", entries);
};
Below sample script will get youtube thumbnail and show it in sheet cells. How can we make sure the cell width/height fit the image width/height? Current script will shrink the image to cell so it's too small.
I try to call autoResizeColumn API but it seems doesn't work for image.
function searchYoutubeByKeyword() {
var results = YouTube.Search.list('id,snippet', {
q:'Cpp',
order:'date',
maxResults: 20
});
var lr = 1;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet1 = ss.getSheetByName("Sheet1");
for (var i = 0; i < results.items.length; i++) {
var item = results.items[i];
Logger.log('[%s] Title: %s', item.id.videoId,item.snippet.publishedAt);
var url = 'http://www.youtube.com/watch?v='+item.id.videoId;
var desc = item.id.videoId;
var link = '=HYPERLINK'+'("' + url+'","'+ desc +'")';
sheet1.getRange(lr, 1).setValue(link);
sheet1.getRange(lr, 2).setValue(item.snippet.publishedAt.substring(0,10));
sheet1.getRange(lr, 3).setValue(item.snippet.title);
var thumbnail = item.snippet.thumbnails["medium"].url;
sheet1.getRange(lr, 4).setValue('=image("'+thumbnail+'")');
lr++;
}
sheet1.getRange(1,1,sheet1.getLastRow(),3).setNumberFormat('#STRING#');
sheet1.autoResizeColumn(4);
}
In my spreadsheet, the cell at reference point (28, 9) contains a hyperlink. The code then copies the contents of that cell to another sheet in the same spreadsheet. Right now it will copy the text, but the new cell only contains the text and not the hyperlink properties. Is there a way to preserve the hyperlink through the transfer? I tried looking up hyperlink information, but could not find an answer...or at least not one I understood. I have only been coding for about 2 weeks, so still not understanding a lot. Here is my code:
function submitButtonClick() {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getActiveSheet();
Logger.log('sheet.getName(): ' + sheet.getName());
if (sheet.getName() !== "SubmitReceipt") {return;};
var targetSheet = ss.getSheetByName("ReceiptRecord");
var arrayOfData = [];
var week = sheet.getRange(6,9).getValue();
var emplN = sheet.getRange(4,9).getValue();
var purDate = sheet.getRange(9,9).getValue();
var purFrom = sheet.getRange(11,9).getValue();
var custC = sheet.getRange(14,9).getValue();
var deptC = sheet.getRange(16,9).getValue();
var lotC = sheet.getRange(18,9).getValue();
var laborC = sheet.getRange(20,9).getValue();
var itemC = sheet.getRange(22,9).getValue();
var hyperL = sheet.getRange(28,9).getValue();
var notes = sheet.getRange(44,8).getValue();
arrayOfData[0] = week;
arrayOfData[1] = emplN;
arrayOfData[2] = purDate;
arrayOfData[3] = purFrom;
arrayOfData[4] = custC;
arrayOfData[5] = deptC;
arrayOfData[6] = lotC;
arrayOfData[7] = laborC;
arrayOfData[8] = itemC;
arrayOfData[9] = notes;
arrayOfData[10] = hyperL;
Logger.log('arrayOfData '+ arrayOfData)
var lastRow = targetSheet.getLastRow();
Logger.log('lastRow: ' + lastRow);
Logger.log('arraylength ' + arrayOfData.length);
targetSheet.getRange(lastRow+1, 1, 1, arrayOfData.length).setValues([arrayOfData]);
sheet.getRange(9,9).clearContent();
sheet.getRange(11,9).clearContent();
sheet.getRange(14,9).clearContent();
sheet.getRange(16,9).clearContent();
sheet.getRange(18,9).clearContent();
sheet.getRange(20,9).clearContent();
sheet.getRange(22,9).clearContent();
sheet.getRange(28,9).clearContent();
sheet.getRange(44,8).clearContent();
}
Thank you in advance for your help.
UPDATE: I did find a possible solution and tried it, but then got an error "TypeError: Cannot find function getFormulaR1C1 in object Sample Receipt 6.jpg. (line 26, file "Submit to Record")."
Here is the updated line 26 to show the new solution I tried:
var url = hyperL.getFormulaR1C1();
Thanks again for helping.
I figured it out. Notice the differences between the "//Changes" comments.
function submitButtonClick() {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getActiveSheet();
Logger.log('sheet.getName(): ' + sheet.getName());
if (sheet.getName() !== "SubmitReceipt") {return;};
var targetSheet = ss.getSheetByName("ReceiptRecord");
var arrayOfData = [];
var week = sheet.getRange(6,9).getValue();
var emplN = sheet.getRange(4,9).getValue();
var purDate = sheet.getRange(9,9).getValue();
var purFrom = sheet.getRange(11,9).getValue();
var custC = sheet.getRange(14,9).getValue();
var deptC = sheet.getRange(16,9).getValue();
var lotC = sheet.getRange(18,9).getValue();
var laborC = sheet.getRange(20,9).getValue();
var itemC = sheet.getRange(22,9).getValue();
var hyperL = sheet.getRange(28,9).getValue();
var notes = sheet.getRange(44,8).getValue();
//Changes
var range = SpreadsheetApp.getActiveSheet().getRange(28,9,1,3);
Logger.log('range= ' + range.getValue());
Logger.log('hyperlink: ' + range.getFormulaR1C1());
var url = /"(.*?)"/.exec(range.getFormulaR1C1())[1];
Logger.log('url: ' + url);
//Changes
arrayOfData[0] = week;
arrayOfData[1] = emplN;
arrayOfData[2] = purDate;
arrayOfData[3] = purFrom;
arrayOfData[4] = custC;
arrayOfData[5] = deptC;
arrayOfData[6] = lotC;
arrayOfData[7] = laborC;
arrayOfData[8] = itemC;
arrayOfData[9] = notes;
arrayOfData[10] = hyperL;
arrayOfData[11] = url;
Logger.log('arrayOfData '+ arrayOfData)
var lastRow = targetSheet.getLastRow();
Logger.log('lastRow: ' + lastRow);
Logger.log('arraylength ' + arrayOfData.length);
targetSheet.getRange(lastRow+1, 1, 1, arrayOfData.length).setValues([arrayOfData]);
sheet.getRange(9,9).clearContent();
sheet.getRange(11,9).clearContent();
sheet.getRange(14,9).clearContent();
sheet.getRange(16,9).clearContent();
sheet.getRange(18,9).clearContent();
sheet.getRange(20,9).clearContent();
sheet.getRange(22,9).clearContent();
sheet.getRange(28,9).clearContent();
sheet.getRange(44,8).clearContent();
}
I'm trying to convert HTML5 table using jspdf (Similar to Export HTML table to pdf using jspdf) .
However, the elements in my table are generated dynamically
function createTable(){
var reportDiv = document.getElementById('customers');
var table = document.createElement('table');
table.id = 'tab_customers';
table.className = 'table table-striped';
var thead = document.createElement('thead');
var tableHeader = document.createElement('th');
tableHeader.innerHTML = "Name";
thead.appendChild(tableHeader);
var tableHeader = document.createElement('th');
tableHeader.innerHTML = "Status";
thead.appendChild(tableHeader);
table.appendChild(thead);
var row = table.insertRow(0);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML = "json";
cell2.innerHTML = "fail";
reportDiv.appendChild(table);
return reportDiv;
}
PDF gets created, but the problem is it fails to show the table header. However if I create the table manually ( copy - paste) from the above dom, table header is rendered.
Any help on this would be highly appreciated. Thanks
th element has to be wrapped around tr element. Then tr is appended to thead, finally to table element.
function createTable(){
var reportDiv = document.getElementById('customers1');
var table = document.createElement('table');
table.id = 'tab_customers1';
table.className = 'table table-striped';
var thead = document.createElement('thead');
var tr = document.createElement('tr');
var tableHeader = document.createElement('th');
tableHeader.innerHTML = "Name";
tr.appendChild(tableHeader);
var tableHeader = document.createElement('th');
tableHeader.innerHTML = "Status";
tr.appendChild(tableHeader);
thead.appendChild(tr);
table.appendChild(thead);
var row = table.insertRow(0);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML = "json";
cell2.innerHTML = "fail";
reportDiv.appendChild(table);
return reportDiv;
}
I have series in the javascript using below code. Getting correct values but it is in Double quotes. So that is the reason I am not getting drilled down chart.
var arrayCodeSeries = <%= serializer.Serialize(ViewData["arrayCodeSeries"]) %>;
i = 0;
for(i=0;i<arrayCodeSeries.length;i++)
{
var temp = arrayCodeSeries[i];
temp = '['.concat(temp,']');
arrayCodeSeries[i] = temp;
}
I am getting
arrayCodeSeries[0] = "['70-158','70-177','70-181']"
data = [{
y: parseInt(arrayTotalCertificateCount[0]),
color: colors[0],
drilldown: {
name: 'Certificate Code',
categories: arrayCodeSeries[0],
data: [2,2,1],
color: colors[0]
}
I tried to remove double quotes with Replace, ReplaceAll and substring functions but it gets me error like it doesn't support these functions.
Help...
Thank you..
attaching here the array :
JS Fiddle with Static data http://jsfiddle.net/xj6ms/1/
According to comment discussion:
You should change your code from:
for(i=0;i<arrayCodeSeries.length;i++) {
var temp = arrayCodeSeries[i];
temp = '['.concat(temp,']');
arrayCodeSeries[i] = temp;
}
to:
var temp = [];
for(i=0;i<arrayCodeSeries.length;i++) {
var items = arrayCodeSeries[i].split(',');
temp.push(items);
}