Protractor excel4node doesn't work - javascript

I'm trying to save some data into my excel:
var xl = require('excel4node');
var wb = new xl.Workbook();
var ws = wb.addWorksheet('abc1');
ws.cell(1,1).string('abc2');
ws.cell(1,2).string('abc3');
ws.cell(1,3).string('abc4');
ws.cell(1,4).string('abc5');
It works fine but when i am trying to:
var a = element(by.className('token')).getText();
ws.cell(2,8).string(a);
I get an error:
Failed: val.match is not a function
I know that "a" return a good string value, because I've checked the logs.

Related

Why do I get this error : Malformed UTF-8 data

const license = fs.readFileSync('./license').toString();
var bytes = CryptoJS.AES.decrypt(license, 'mysecretkey123');
var originalText = bytes.toString(CryptoJS.enc.Utf8);
Last line throws an error : Malformed UTF-8 data
It works without error when I run this code in my Electron app before packaging it, but once its packaged in a exe file it throws an error here
The ./license file was created this way :
var licensedata = {license:licen.license, lastpayment:data.lastpayment, macAddress:getmac.default()};
var stringtoencrypt = JSON.stringify(licensedata);
var ciphertext = CryptoJS.AES.encrypt(stringtoencrypt, 'f8LNLIHdb9CT4KYTBF6Az9sNR2r1bMlUjqgCia0teIrg0lZ4iZ7sUSBt7cJqmYE3GrHe082eD9ajIry2');
var cptext = ciphertext.toString();
var fp = "./license";
var encdata = new Uint8Array(Buffer.from(cptext));
fs.writeFileSync(fp, encdata);

How to display data from localstorage using handlebars?

In my program i fetch data from console and store it in localstorage and webSQL . Now i want to display the stored data from localstorage using handlebar. I used the following code:
console.log(response); // To get data from console
var offer = JSON.stringify(response);
localStorage.setItem("object",offer); // saved in localstorage
var seasons= localStorage.getItem("object"); // get data from localstorage and saved in variable seasons
var mysource = document.getElementById("detailstemplate").innerHTML;
var mytemplate = Handlebars.compile(mysource);
var myresult = mytemplate(seasons);
document.getElementById("divOffers").innerHTML = myresult;
I used the last 4 lines to display data using handlebars. But it is not working. Please correct the error.Can anyone help with this?
var season = localStorage.getItem("cart");
var season2 = $.parseJSON(season);
var mytemp = $("#mainmenu-template").html(); // Grab the template script
var ourtemp = Handlebars.compile(mytemp); // Compile the template
var resultnew = ourtemp(season2);
$("#divMainMenu").append(resultnew);

Apps script write to Big Query unknown error

This is supposed to read in a CSV and then write it to bigquery. When it runs, however, nothing is written, and there are no errors logged. I read that I need to write a csv and then turn it into an Octet Stream. I am not sure whether or not this is compatible with google bigquery.
function test(){
try{
var tableReference = BigQuery.newTableReference();
tableReference.setProjectId(PROJECT_ID);
tableReference.setDatasetId(datasetId);
tableReference.setTableId(tableId);
var schema = "CUSTOMER:string, CLASSNUM:integer, CLASSDESC:string, CSR:string, CSR2:string, INSURANCE:string, REFERRALGENERAL:string, REFERRALSPECIFIC:string, NOTES:string, INMIN:integer, INHR:integer, OUTMIN:integer, OUTHR:integer, WAITMIN:integer, WAITHR:integer, DATETIMESTAMP:float, DATEYR:integer,DATEMONTH:integer, DATEDAY:integer";
var load = BigQuery.newJobConfigurationLoad();
load.setDestinationTable(tableReference);
load.setSourceUris(URIs);
load.setSourceFormat('NEWLINE_DELIMITED_JSON');
load.setSchema(schema);
load.setMaxBadRecords(0);
load.setWriteDisposition('WRITE_TRUNCATE');
var configuration = BigQuery.newJobConfiguration();
configuration.setLoad(load);
var newJob = BigQuery.newJob();
newJob.setConfiguration(configuration);
var loadr = DriveApp.getFilesByName("test.csv");
var x = loadr.next().getBlob();
Logger.log(x.getDataAsString());
var d = DriveApp.getFilesByName("test.csv");
var id = d.next().getId();
Logger.log(id);
var data = DocsList.getFileById(id).getBlob().getDataAsString();
var mediaData = Utilities.newBlob(data, 'application/octet-stream');
BigQuery.Jobs.insert(newJob, PROJECT_ID, mediaData)
}
catch(error){Logger.log("A" + error.message);}
}
Your sourceFormat is wrong for CSV files:
The format of the data files. For CSV files, specify "CSV". For
datastore backups, specify "DATASTORE_BACKUP". For newline-delimited
JSON, specify "NEWLINE_DELIMITED_JSON". The default value is CSV.
https://developers.google.com/bigquery/docs/reference/v2/jobs#configuration.load.sourceUris
On the other hand I think you don't need at all the load.setSourceUris(URIs); since you try to load from local file, and not from Google Cloud Storage. Check this python example https://developers.google.com/bigquery/loading-data-into-bigquery

Titanium mobile - Uncaught Error: no such table

I am having a terrible time trying to figure out why I keep getting this error. I have searched this and other forums and no answer seems to be able to help so I will ask here.
I am trying to create a basic photo catalogue app for Android using Titanium. The catalogue info is strore in an sqlite database.
I can create the database OK - I can access some info from it in one window. When I then go to another window and try to get further info from the table it gives me the error:
Uncaught error: no such table: photos:, while compiling SELECT..........
See code below:
This is the first window that opens from app.js
The table shows up fine here - NO errors
// create var for the currentWindow
var currentWin = Ti.UI.currentWindow;
// set the data from the database to the array
//function setData() {
// create table view
var tableview = Ti.UI.createTableView({
});
//var db = Ti.Database.open('catalogue');
//db.remove();
var db = Ti.Database.install('catalogue.sqlite','photos');
var rows = db.execute('SELECT * FROM photos GROUP BY title');
// create the array
var dataArray = [];
while(rows.isValidRow()) {
var title = rows.fieldByName('title');
var id = rows.fieldByName('id');
dataArray.push({title:title, id:id, url:'catalogue_detail.js'});
rows.next();
}
tableview.setData(dataArray);
// add the tableView to the current window
currentWin.add(tableview);
tableview.addEventListener('click', function(e){
if (e.rowData.url)
{
var win = Ti.UI.createWindow({
id:e.rowData.id,
title:e.rowData.title,
url:e.rowData.url
});
win.open();
}
});
// call the setData function to attach the database results to the array
//setData();
I then open catalogue_detail.js from the above and I get the error
catalogue_detail.js
var win = Titanium.UI.currentWindow;
var id = win.id
var tableview = Titanium.UI.createTableView({
});
var db = Titanium.Database.open('catalogue.sqlite');//I have chanegd this to 'photos' and I get the same error
var sql = db.execute('SELECT title, location, photographer FROM photos where id="' + id + '"');
var title = sql.fieldByName('title');
var location = sql.fieldByName('location');
var photographer = sql.fieldByName('photographer');
// create the array
var dataArray = [];
while(sql.isValidRow()) {
var title = sql.fieldByName('title');
var location = sql.fieldByName('location');
var photographer = sql.fieldByName('photographer');
dataArray.push({title:title, location:location, photographer:photographer});
sql.next();
}
tableview.setData(dataArray);
win.add(tableview);
So the table in my database called 'photos' open in one window then I get the error trying to open the same database?
I have uninstalled the app, recreated the database, renamed tables etc but still the same error...
I am sure it is a simple thing I am missing but I am very confused!
Thanks for any assistance.
JC
Try absolute path: Ti.Database.open('catalogue.sqlite'); and Ti.Database.install('/catalogue.sqlite');.
Also remember about closing connection to database when you retrieve all data from query:
sql.close();
db.close();

Writing json string into file using Windows Script Host

I am trying to write json string that I stringified using https://github.com/douglascrockford/JSON-js/blob/master/json2.js ( JSON.stringify) ,
I am trying to save the string and I am getting an error:
Microsoft JScript Runtime Error: Invalid procedure call or argument
at
var textStream = fileObj.OpenAsTextStream(ForWriting, TristateFalse);
this is my code :
var pref = JSON.parse(textPref);
textPref = JSON.stringify(pref);
WSH.echo(textPref)
// Create the new file.
fso.CreateTextFile("d:\\Preferences_temp", true);
var fileObj = fso.GetFile("d:\\Preferences_temp");
var textStream = fileObj.OpenAsTextStream(ForWriting, TristateFalse); <- Microsoft JScript Runtime Error: Invalid procedure call or argument
textStream.Write(textPref);
textStream.Close();
The constants you pass to the FSO methods are not exposed via late binding with new ActiveXObject so you need to define them independently;
var ForWriting = 2;
var TristateFalse = 0;
Edit
var ForWriting = 2;
var TristateTrue = -1;
var textPref = '{"xxx": "AA \u05D5 BB"}';
var pref = JSON.parse(textPref);
textPref = JSON.stringify(pref)
// Create the new file.
var fso = new ActiveXObject("Scripting.FileSystemObject");
//create as unicode
fso.CreateTextFile("c:\\null\\Preferences_temp", true, true);
var fileObj = fso.GetFile("c:\\null\\Preferences_temp");
//open for unicode
var textStream = fileObj.OpenAsTextStream(ForWriting, TristateTrue);
textStream.Write(textPref);
textStream.Close();

Categories

Resources