alasql export to xlsx remove hashkey - export-to-excel

I am using angularjs and javascript and want to export two arrays to Excel using alasql. The Excel file has two sheets, on every sheet there is one array.
In my Excel result I find an extra column $$hashkey.
According to the information I found, using angularjs, the $$hashkey is automatically removed. I also tried adding 'alasql.options.angularjs' but it did not help.
What am I doing wrong?
I am using the two arrays like this:
$scope.ExecutionsLC1: [[Execution,1,2,3],[Operators,1014,1019,1020],[Result,X,X,V]];
$scope.ExecutionsLC2: [[Execution,1,2,3],[Operators,2014,2019,2020],[Result,X,X,V]];
var opts = [{sheetid:'LC1',header:false},{sheetid:'LC2',header:false}];
var res = alasql('SELECT INTO XLSX("LCDetail.xlsx",?) FROM ?',[opts,[$scope.ExecutionsLC1,$scope.ExecutionsLC2]]);

it seems I can use angular.copy() to remove the $$hashkey.
var data1 = angular.copy($scope.ExecutionsLC1);
var data2 = angular.copy($scope.ExecutionsLC2);
var opts = [{sheetid:'One',header:false},{sheetid:'Two',header:false}];
var res = alasql('SELECT INTO XLSX("restest344b.xlsx",?) FROM ?',
[opts,[data1,data2]]);

Related

How to add static information to dynamic data in Google Sheets?

I'm importing data into Google Sheets and then adding static information to it. I'd like my static data to be kept in alignment with a dynamic - is this possible? Is a script still required? Does anyone have an example?
it depends on your data structure, but there is a way with VLOOKUP formula
https://exceljet.net/excel-functions/excel-vlookup-function
Did you already find your solution to the problem? It sounds like you sort be able to sort the data with filters and still keep your note columns aligned.
this script could perhaps help:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");
var range = sheet.getRange("A1:Z");
function onEdit(e) {
range.sort([{column: 2, ascending: false}]);
}
Sheet1 = name of the sheet
A1:Z = range to be sorted
column: 2 = column B
ascending: false = descending

To get value of key from cache using CacheService in google app script

I am trying to implement caching. I've written code in bounded script of spreadsheet. It's working fine i.e. I am able to get values against particular key. But this code is valid only for bounded script.
Does anyone know that how to access value against particular key from separate script?
Code to put in cache:(Bounded Script)
var sp_key = '1231232';
var ss = SpreadsheetApp.openById(sp_Key);
var s = ss.getSheetByName("test_Sheet");
var cache = CacheService.getScriptCache();
var val= "xyz"
cache.put(A, val);
var cache = CacheService.getPublicCache();
Logger.log(cache.get(A));
Above code works fine. But if I want to get the value from unbounded script then what is the best way?
The getScriptCache() method also works in a stand alone Apps Script project.
There is an error in your code. A is not defined. Either put quotes around A or define A as a variable, and assign a value
function scriptCache() {
var sp_key = '1231232';
//var ss = SpreadsheetApp.openById(sp_Key);
//var s = ss.getSheetByName("test_Sheet");
var cache = CacheService.getScriptCache();
var val= "xyz"
cache.put('A', val);
var cache = CacheService.getPublicCache();
Logger.log(cache.get('A'));
}
I ran that code in a stand alone Apps Script and it works.

Get query string in Google CSE v2

I am using Google CSE v2, and I need to get the query that the user entered. The problem is that it is ajax, and the query is not in the url.
Does anyone know a solution?
Thanks
First off, when you create the search box, you need to give it a 'gname' attribute so you can identify it in your javascript, like so:
<gcse:searchbox gname="storesearch"></gcse:searchbox>
<gcse:searchresults gname="storesearch"></gcse:searchresults>
Or, if you're using the html5 style tags (which you should unless you have a reason not to):
<div class="gcse-searchbox" data-gname="storesearch"></div>
<div class="gcse-searchresults" data-gname="storesearch"></div>
(Replace 'storesearch' with whatever name you want to use to identify this custom search.)
More info on that here: https://developers.google.com/custom-search/docs/element#supported_attributes
Then, you can access the custom search element and get the current query like so:
var cseElement = google.search.cse.element.getElement('storesearch'),
query = cseElement.getInputQuery();
or if you don't need the reference to the element anymore, obviously that could be combined into one line:
var query = google.search.cse.element.getElement('storesearch').getInputQuery();
The docs for that part are here: https://developers.google.com/custom-search/docs/element#cse-element
I know this is already answered correctly. But for those also looking for a simple JS function to achieve this, here you go. Pass it the name of the variable you want to extract from the query string.
var qs = (function(a) {
if (a == "") return {};
var b = {};
for (var i = 0; i < a.length; ++i) {
var p=a[i].split('=');
if (p.length != 2) continue;
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
}
return b;
})(window.location.search.substr(1).split('&'));

LinqToExcel - Need to start at a specific row

I'm using the LinqToExcel library. Working great so far, except that I need to start the query at a specific row. This is because the excel spreadsheet from the client uses some images and "header" information at the top of the excel file before the data actually starts.
The data itself will be simple to read and is fairly generic, I just need to know how to tell the ExcelQueryFactory to start at a specific row.
I am aware of the WorksheetRange<Company>("B3", "G10") option, but I don't want to specify an ending row, just where to start reading the file.
Using the latest v. of LinqToExcel with C#
I just tried this code and it seemed to work just fine:
var book = new LinqToExcel.ExcelQueryFactory(#"E:\Temporary\Book1.xlsx");
var query =
from row in book.WorksheetRange("A4", "B16384")
select new
{
Name = row["Name"].Cast<string>(),
Age = row["Age"].Cast<int>(),
};
I only got back the rows with data.
I suppose that you already solved this, but maybe for others - looks like you can use
var excel = new ExcelQueryFactory(path);
var allRows = excel.WorksheetNoHeader();
//start from 3rd row (zero-based indexing), length = allRows.Count() or computed range of rows you want
for (int i = 2; i < length; i++)
{
RowNoHeader row = allRows.ElementAtOrDefault(i);
//process the row - access columns as you want - also zero-based indexing
}
Not as simple as specifying some Range("B3", ...), but also the way.
Hope this helps at least somebody ;)
I had tried this, works fine for my scenario.
//get the sheets info
var faceWrksheet = excel.Worksheet(facemechSheetName);
// get the total rows count.
int _faceMechRows = faceWrksheet.Count();
// append with End Range.
var faceMechResult = excel.WorksheetRange<ExcelFaceMech>("A5", "AS" + _faceMechRows.ToString(), SheetName).
Where(i => i.WorkOrder != null).Select(x => x).ToList();
Have you tried WorksheetRange<Company>("B3", "G")
Unforunatly, at this moment and iteration in the LinqToExcel framework, there does not appear to be any way to do this.
To get around this we are requiring the client to have the data to be uploaded in it's own "sheet" within the excel document. The header row at the first row and the data under it. If they want any "meta data" they will need to include this in another sheet. Below is an example from the LinqToExcel documentation on how to query off a specific sheet.
var excel = new ExcelQueryFactory("excelFileName");
var oldCompanies = from c in repo.Worksheet<Company>("US Companies") //worksheet name = 'US Companies'
where c.LaunchDate < new DateTime(1900, 0, 0)
select c;

firefox extension localStorage problem

I tried to save values in localStorage but it does not work. Maybe I forgot something. First I was thinking localStorage was not enough so I extended it to window.localStorage. Do I have to call some special library to access it? My Firefox version is above 3.5.
Here is my code:
var ID1 = document.getElementById("id1");
var ID2 = document.getElementById("id2");
window.localStorage.setItem("IDF",JSON.stringify(ID1));
window.localStorage.setItem("IDS",JSON.stringify(ID2));
var RUN1 = JSON.parse(window.localStorage.getItem("IDF"));
var RUN2 = JSON.parse(window.localStorage.getItem("IDS"));
alert(RUN1 + RUN2);
hmmm,
found the problem:
window.content.localStorage.setItem
you can skip JSON too if you assign the object value to the variables:
var IDF = ID1.value

Resources