Alasql: Excel file : how to custom header with the name of index from javascript array

Created on 7 Mar 2016  路  11Comments  路  Source: agershun/alasql

Hii,

I would like custom my header with the name of index from javascript array

{"Blog international": [
{
"email":"[email protected]",
"mark":31.25,
"coef":1
},
{
"email":"[email protected]",
"mark":49.24,
"coef":1
},{
"email":"[email protected]",
"mark":50,
"coef":1
}],
"PowerPoint":[
{
"email":"[email protected]",
"mark":31.25,
"coef":1
},
{
"email":"[email protected]",
"mark":49.24,
"coef":1
},{
"email":"[email protected]",
"mark":50,
"coef":1
}],
"Culture WEB":[
{
"email":"[email protected]",
"mark":31.25,
"coef":1
},
{
"email":"[email protected]",
"mark":49.24,
"coef":1
},{
"email":"[email protected]",
"mark":50,
"coef":1
}]}

I want get a Excel file like this :

Email | Blog international | PowerPoint | Culture WEB
[email protected]  |  31.25 |  31.25 |  31.25
[email protected]  | 49.2 | 49.2 | 49.2
[email protected]  | 50 | 50 | 50

Any ideas how to do that ?

Most helpful comment

@Dosix Ahh, That changes things. What we need to do is generate the query with javascript to have the indexed dynamic.
https://jsfiddle.net/kprk8dh1/10/
Should work for you.

All 11 comments

Something like this:
https://jsfiddle.net/kprk8dh1/6/
Although, it seems as though there is an error somewhere in alasql causing XLSXML to fail.
@mathiasrw
Thoughts on why this might be failing with this error?

Hi @nbdamian

Will they always have the same number of data?

@nbdamian yeah but the name of index is dynamic, I can't put the name like your example in my query :/

I can manipulate my json if needed

Could you supply an example of the name of the index being dynamic?

Sent using Boxer

On 15/03/2016 9:12 PM, Ludovic Fgt [email protected] wrote:

@nbdamianhttps://github.com/nbdamian yeah but the name of index is dynamic, I can't put the name like your example in my query :/

I can manipulate my json if needed

You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
https://github.com/agershun/alasql/issues/615#issuecomment-196710775

@mathiasrw I would expect the number of data would be dynamic.

@mathiasrw
It seems as though an opts object is required. I believe we need a workaround to make it not required.
in the alasql.into.XLSXML function,
Directly after

if(typeof filename == 'object') {
    opts = filename;
    filename = undefined;
}

add

  opts = opts || {}

@Dosix
https://jsfiddle.net/kprk8dh1/7/
Should now Download.

@nbdamian Nice spotted!

Please test the last version to see if it solved the problem: https://github.com/agershun/alasql/blob/develop/dist/alasql.js

Perfect. That update fixed the issue of not being able to save,
Though leave the issue open as it started as a request for help writing a query.

@nbdamian It's almost what I need, so when i said my indexes are dynamic, i meant by example : "Blog international", "Power Point"...etc can change

@Dosix Ahh, That changes things. What we need to do is generate the query with javascript to have the indexed dynamic.
https://jsfiddle.net/kprk8dh1/10/
Should work for you.

Thank you so #much, it works perfectly :+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AmyBlankenship picture AmyBlankenship  路  6Comments

karubimania picture karubimania  路  6Comments

peon501 picture peon501  路  5Comments

mathiasrw picture mathiasrw  路  5Comments

mwhebert picture mwhebert  路  3Comments