How to process batchUpdate and copy from one spreadsheet into another using Google Sheets API - google-sheets-api

Link to original question where I found the below script: How to batch-copy range with Google Sheets Api
Question: How do I modify the below to write into a different spreadsheetId? I've Googled everything I can and can only find examples where the copyPaste occurs within the same SpreadsheetID.
function Test_Copy() {
var spreadsheetId = "1hLXq9zq-tAaGpPtGiY6859h4oKxIbNimxCHPPZOzdE0";
var sheetId = "1792457718";
var sheetIdd = "760382355";
var rangeFrom = Sheets.newGridRange();
rangeFrom.sheetId = sheetId;
rangeFrom.startRowIndex = 0;
rangeFrom.endRowIndex = 23637;
rangeFrom.startColumnIndex = 0;
rangeFrom.endColumnIndex = 23;
var rangeTo = Sheets.newGridRange();
rangeTo.sheetId = sheetIdd;
rangeTo.startRowIndex = 0;
rangeTo.endRowIndex = 23637;
rangeTo.startColumnIndex = 0;
rangeTo.endColumnIndex = 23;
var copyPasteRequest = Sheets.newCopyPasteRequest();
copyPasteRequest.destination = rangeTo;
copyPasteRequest.source = rangeFrom;
copyPasteRequest.pasteType = "PASTE_VALUES";
copyPasteRequest.pasteOrientation = "NORMAL";
var resource = Sheets.newBatchUpdateSpreadsheetRequest();
//Create request object
var request = Sheets.newRequest();
request.copyPaste = copyPasteRequest;
resource.requests = [request];
var res = Sheets.Spreadsheets.batchUpdate(resource , spreadsheetId);
//Logger.log(res.replies);
//Logger.log(res.spreadsheetId);
}

Related

Loop over path points in Photoshop

I'm trying to iterate over a create path in Photoshop finding out the anchor points position etc
var srcDoc = app.activeDocument;
// create the array of PathPointInfo objects
var lineArray = new Array();
lineArray.push(new PathPointInfo());
lineArray[0].kind = PointKind.CORNERPOINT;
lineArray[0].anchor = new Array(20, 160);
lineArray[0].leftDirection = [35, 200];
lineArray[0].rightDirection = lineArray[0].anchor;
lineArray.push(new PathPointInfo());
lineArray[1].kind = PointKind.CORNERPOINT;
lineArray[1].anchor = new Array(20, 40);
lineArray[1].leftDirection = lineArray[1].anchor;
lineArray[1].rightDirection = [220, 260];
// create a SubPathInfo object, which holds the line array in its entireSubPath property.
var lineSubPathArray = new Array();
lineSubPathArray.push(new SubPathInfo());
lineSubPathArray[0].operation = ShapeOperation.SHAPEXOR;
lineSubPathArray[0].closed = false;
lineSubPathArray[0].entireSubPath = lineArray;
//create the path item, passing subpath to add method
var myPathItem = srcDoc.pathItems.add("A Line", lineSubPathArray);
for (var i = 0; i < lineSubPathArray[0].entireSubPath.length; i++)
{
var b = lineSubPathArray[0].entireSubPath[i].anchor;
alert(b);
}
This works fine, but instead of creating the path and finding out it's information I want to loop over each path and get the same. This should be the same as the loop above only without explicitly calling lineSubPathArray and its parts.
for (var i = 0; i < srcDoc.pathItems[0].subPathItems.pathPoints.length; i++) // wrong I think
{
var b = srcDoc.pathItems[0].entireSubPath[i].anchor; // wrong
alert(b);
}
Almost: you need to iterate through subPathItems which consist of pathPoints:
var srcDoc = activeDocument;
var workPath = srcDoc.pathItems[0];
var i, k, b;
for (i = 0; i < workPath.subPathItems.length; i++) {
for (k = 0; k < workPath.subPathItems[i].pathPoints.length; k++) {
b = workPath.subPathItems[i].pathPoints[k].anchor;
alert(b);
}
}

Set resolution when exporting artboards to PNG using script

Sorry that this is so similar to a recent post but I can't find the solution anywhere. I have created a simple script that loops through each artboard in an open illustrator document and exports it as a separate PNG file. All is working well except that I want to set the resolution to 150 dpi and not the default 72 dpi, for production reasons. This is an option that you can set when exporting manually to PNG but I don't seem to be able to set it in the PNG options in the code, although the script runs without errors it ignores the resolution setting. Could someone let me know how to do this, many thanks. Code as follows:
var doc = app.activeDocument;;//Gets the active document
var fileName = doc.name.slice(0, 9);//Gets the G Number
var numArtboards = doc.artboards.length;//returns the number of artboards in the document
var filePath = (app.activeDocument.fullName.parent.fsName).toString().replace(/\\/g, '/');
var options = new ExportOptionsPNG24();
for (var i = 0; i < numArtboards; i++ ) {
doc.artboards.setActiveArtboardIndex( i );
options.artBoardClipping = true;
options.matte = false;
options.horizontalScale = 100;
options.verticalScale = 100;
options.transparency = true;
var artboardName = doc.artboards[i].name;
//$.writeln("artboardName= ", artboardName);
var destFile = new File(filePath + "/" + fileName + " " + artboardName + ".png");
//$.writeln("destFile= ",destFile);
doc.exportFile(destFile,ExportType.PNG24,options);
}
After doing some digging I've found that if you use imageCapture you can set the resolutuion. So new script below. thanks to CarlosCanto for providing this link via the Adobe Forum https://forums.adobe.com/message/9075307#9075307
var doc = app.activeDocument;;//Gets the active document
var fileName = doc.name.slice(0, 9);//Gets the G Number
var numArtboards = doc.artboards.length;//returns the number of artboards in the document
var filePath = (app.activeDocument.fullName.parent.fsName).toString().replace(/\\/g, '/');
var options = new ImageCaptureOptions();
for (var i = 0; i < numArtboards; i++) {
doc.artboards.setActiveArtboardIndex(i);
var activeAB = doc.artboards[doc.artboards.getActiveArtboardIndex()];
options.artBoardClipping = true;
options.resolution = 150;
options.antiAliasing = true;
options.matte = false;
options.horizontalScale = 100;
options.verticalScale = 100;
options.transparency = true;
var artboardName = doc.artboards[i].name;
var destFile = new File(filePath + "/" + fileName + " " + artboardName + ".png");
doc.imageCapture(destFile, activeAB.artboardRect, options);
}

Authentication lost Google app script

I have created a a google app script that create a pdf from a google sheet and send it via email.
I have three script that work perfectly. But with the fourth script (identical to the other)I lost always the authorization after about one - two hours.
Has someone the same problem?
Thanks
Pasquale
Attached code. I use a trigger to lunch code every time the form is submitted.
// When Form Gets submitted
function onFormSubmit(e) {
var docTemplate = "1mI4SQQe4muuW386jgzkxBlZBWuH0OBRdbz1hItOPjK4";
var docName = "DDT";
var ss = SpreadsheetApp.openById("1HzZFDJYAU6H1pptqcA5fEAVelkZw1LP7si9bBrsF_u0")
var sheet = ss.getSheets()[0];
var lastrow = ss.getLastRow();
var d = new Date ();
var id ="0B1-7TPSHWZ1bMlNLTV9tTFJNb2c"; // cartella Raccolta DDT
var folder = DriveApp.getFolderById(id);
//Get information from form and set as variables
//var email = "pasquale.martucci#decathlon.com";
var email = e.values[1];
var mittente = e.values[2];
var destinatario = e.values[3];
var primaQnt = e.values[4];
var primaDescr = e.values[5];
var secondaQnt = e.values[6];
var secondaDescr = e.values[7];
var terzaQnt = e.values[8];
var terzaDescr = e.values[9];
var quartaQnt = e.values[10];
var quartaDescr = e.values[11];
var quintaQnt = e.values[12];
var quintaDescr = e.values[13];
var aspetto = e.values[14];
var colli = e.values[15];
var peso = e.values[16];
var vettore = e.values[17];
// Ricava indirizzi e città
var cell1 = sheet.getRange("S"+lastrow);
cell1.setFormula("=VLOOKUP(C"+lastrow+";Foglio2!A1:C35;2;FALSE)");
var indirMitt = cell1.getValue()
var cell2 = sheet.getRange("T"+lastrow);
cell2.setFormula("=VLOOKUP(C"+lastrow+";Foglio2!A1:C35;3;FALSE)");
var citMitt = cell2.getValue()
var cell3 = sheet.getRange("U"+lastrow);
cell3.setFormula("=VLOOKUP(D"+lastrow+";Foglio2!A1:C35;2;FALSE)");
var indirDest = cell3.getValue()
var cell4 = sheet.getRange("V"+lastrow);
cell4.setFormula("=VLOOKUP(D"+lastrow+";Foglio2!A1:C35;3;FALSE)");
var citDest = cell4.getValue()
//Ricava data
var day = sheet.getRange("W"+lastrow);
day.setFormula("=(DAY(A"+lastrow+"))");
var month = sheet.getRange("X"+lastrow);
month.setFormula("=(MONTH(A"+lastrow+"))");
var year = sheet.getRange("Y"+lastrow);
year.setFormula("=(YEAR(A"+lastrow+"))");
var day1 = sheet.getRange("W"+lastrow).getValue();
var month1 = sheet.getRange("X"+lastrow).getValue();
var year1 = sheet.getRange("Y"+lastrow).getValue();
var data = day1+"/"+month1+"/"+year1;
// Get document template, copy it as a new temp doc, and save the Doc’s id
var copyId = DriveApp.getFileById(docTemplate)
.makeCopy(docName+' N° '+lastrow+' ' +mittente , folder)
.getId();
// Open the temporary document
var copyDoc = DocumentApp.openById(copyId);
// Get the document’s body section
var copyBody = copyDoc.getActiveSection();
// Replace place holder keys,in our google doc template
copyBody.replaceText('keyMittente', mittente);
copyBody.replaceText('keyDestinatario', destinatario);
copyBody.replaceText('keyQNT1', primaQnt);
copyBody.replaceText('keyDescrizione1', primaDescr);
copyBody.replaceText('keyQNT2', secondaQnt);
copyBody.replaceText('keyDescrizione2',secondaDescr);
copyBody.replaceText('keyQNT3', terzaQnt);
copyBody.replaceText('keyDescrizione3', terzaDescr);
copyBody.replaceText('keyQNT4', quartaQnt);
copyBody.replaceText('keyDescrizione4', quartaDescr);
copyBody.replaceText('keyQNT5', quintaQnt);
copyBody.replaceText('keyDescrizione5', quintaDescr);
copyBody.replaceText('keyAspetto', aspetto);
copyBody.replaceText('keyKg', peso);
copyBody.replaceText('keyColli', colli);
copyBody.replaceText('keyVettore', vettore);
copyBody.replaceText('keyIndirMitt', indirMitt);
copyBody.replaceText('keyCitMitt', citMitt);
copyBody.replaceText('keyIndirDest', indirDest);
copyBody.replaceText('keyCitDest', citDest);
copyBody.replaceText('keyNum', lastrow);
copyBody.replaceText('keyData', data);
// Save and close the temporary document
copyDoc.saveAndClose();
// Convert temporary document to PDF by using the getAs blob conversion
var pdf = DriveApp.getFileById(copyId).getAs("application/pdf");
// Attach PDF and send the email
var subject = "DDT";
var body = "In allegato il DDT generato tramite il portale SimplyCar.";
GmailApp.sendEmail(email, subject, body, {htmlBody: body, attachments: pdf});
// Delete temp file
// DriveApp.getFileById(copyId).setTrashed(true);
}

How to get Rates from UPS Rate API?

I am using nopcommerce 3.5. I have added plugin of UPS of TransitInTime and Rate API. I want to get rates by calling UPS Rate API. I want all Rates in dropdown on page load.
So for the first I am using test application using webservices of RateWebReference and in which I get only one Rate but I want Rates for all shipping option.
Here is my code of RateWSClient.cs
RateService rate = new RateService();
RateRequest rateRequest = new RateRequest();
UPSSecurity upss = new UPSSecurity();
UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken();
upssSvcAccessToken.AccessLicenseNumber = "CC....";
upss.ServiceAccessToken = upssSvcAccessToken;
UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken();
upssUsrNameToken.Username = "gi..";
upssUsrNameToken.Password = "Ch..";
upss.UsernameToken = upssUsrNameToken;
rate.UPSSecurityValue = upss;
RequestType request = new RequestType();
String[] requestOption = { "Rate" };
request.RequestOption = requestOption;
rateRequest.Request = request;
ShipmentType shipment = new ShipmentType();
ShipperType shipper = new ShipperType();
shipper.ShipperNumber = "A65V88";
RateWSSample.RateWebReference1.AddressType shipperAddress = new RateWSSample.RateWebReference1.AddressType();
String[] addressLine = { "", "", "" };
shipperAddress.AddressLine = addressLine;
shipperAddress.City = "";
shipperAddress.PostalCode = "30076";
shipperAddress.StateProvinceCode = "GA";
shipperAddress.CountryCode = "US";
shipperAddress.AddressLine = addressLine;
shipper.Address = shipperAddress;
shipment.Shipper = shipper;
ShipFromType shipFrom = new ShipFromType();
RateWSSample.RateWebReference1.AddressType shipFromAddress = new RateWSSample.RateWebReference1.AddressType();
shipFromAddress.AddressLine = addressLine;
shipFromAddress.City = "";
shipFromAddress.PostalCode = "30076";
shipFromAddress.StateProvinceCode = "GA";
shipFromAddress.CountryCode = "US";
shipFrom.Address = shipFromAddress;
shipment.ShipFrom = shipFrom;
ShipToType shipTo = new ShipToType();
ShipToAddressType shipToAddress = new ShipToAddressType();
String[] addressLine1 = { "", "", "" };
shipToAddress.AddressLine = addressLine1;
shipToAddress.City = "";
shipToAddress.PostalCode = "92262";
shipToAddress.StateProvinceCode = "";
shipToAddress.CountryCode = "US";
shipTo.Address = shipToAddress;
shipment.ShipTo = shipTo;
CodeDescriptionType service = new CodeDescriptionType();
//Below code uses dummy date for reference. Please udpate as required.
service.Code = "02";
shipment.Service = service;
PackageType package = new PackageType();
PackageWeightType packageWeight = new PackageWeightType();
packageWeight.Weight = "125";
CodeDescriptionType uom = new CodeDescriptionType();
uom.Code = "LBS";
uom.Description = "pounds";
packageWeight.UnitOfMeasurement = uom;
package.PackageWeight = packageWeight;
CodeDescriptionType packType = new CodeDescriptionType();
packType.Code = "02";
package.PackagingType = packType;
PackageType[] pkgArray = { package };
shipment.Package = pkgArray;
//Shipping Rate Chart
// ShipmentRatingOptionsType SRO = new ShipmentRatingOptionsType();
//SRO.RateChartIndicator = "";
//shipment.ShipmentRatingOptions= SRO;
//rateRequest.Shipment = shipment;
ShipmentRatingOptionsType SRO = new ShipmentRatingOptionsType();
SRO.NegotiatedRatesIndicator = "";
shipment.ShipmentRatingOptions = SRO;
rateRequest.Shipment = shipment;
System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
Console.WriteLine(rateRequest);
RateResponse rateResponse = rate.ProcessRate(rateRequest);
Console.WriteLine("The transaction was a " + rateResponse.Response.ResponseStatus.Description);
Console.WriteLine("Total Shipment Charges " + rateResponse.RatedShipment[0].TotalCharges.MonetaryValue + rateResponse.RatedShipment[0].TotalCharges.CurrencyCode);
Console.ReadKey();
I have resolved this questions. So If you face this kind of problem don't forget to use
String[] requestOption = { "Shop" };
in place of
String[] requestOption = { "Rate" };
Then you will get rates for all shipping options.

Lucene 30 fuzzy search

I user LUCENE_30 for my search engine but i cannot make fuzzy search.How can i make it work?
I tried use GetFuzzyQuery but nothing happens.As i see is not supported.
Here my code :
if (searchQuery.Length < 3)
{
throw new ArgumentException("none");
}
FSDirectory dir = FSDirectory.Open(new DirectoryInfo(_indexFileLocation));
var searcher = new IndexSearcher(dir, true);
var analyzer = new RussianAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
var query = MultiFieldQueryParser.Parse(Lucene.Net.Util.Version.LUCENE_30, searchQuery, new[] {"Title" }, new[] { Occur.SHOULD }, analyzer);
var hits = searcher.Search(query, 11110);
var dto = new PerformSearchResultDto();
dto.SearchResults = new List<SearchResult>();
dto.Total = hits.TotalHits;
for (int i = pagesize * page; i < hits.TotalHits && i < pagesize * page + pagesize; i++)
{
// Document doc = hits.Doc(i);
int docId = hits.ScoreDocs[i].Doc;
var doc = searcher.Doc(docId);
var result = new SearchResult();
result.Title = doc.Get("Title");
result.Type = doc.Get("Type");
result.Href = doc.Get("Href");
result.LastModified = doc.Get("LastModified");
result.Site = doc.Get("Site");
result.City = doc.Get("City");
//result.Region = doc.Get("Region");
result.Content = doc.Get("Content");
result.NoIndex = Convert.ToBoolean(doc.Get("NoIndex"));
dto.SearchResults.Add(result);
}
Fuzzy queries certainly are supported. See the FuzzyQuery class.
The query parser also supports fuzzy queries, simply with a tilde appended: misspeled~