0

I want jquery or javascript code to get the data from excel and add them to array in jquery. Example: In column "A" there are names, Kasun Nirmala Gemba John

And I want to add then to Var names=['Kasun', 'Nirmala','Gemba','John']

This is what I have tried. In this I get all data of excel to #res div. But I want to get them all to an array

alasql('SELECT * into html("#res") from xlsx("excel.xlsx")');
<script type="text/javascript" src="js/alasql.min.js"></script>
<script type="text/javascript" src="js/xlsx.core.min.js"></script>

<div id="res"></div>
KNB
  • 97
  • 3
  • 9
  • What code have you tried? What errors are you getting? Where is the spreadsheet coming from? – Arcath Dec 03 '15 at 15:24

1 Answers1

0

You need to make a new cell in your excel file and use concatenate, there is a function helper the parts would be like:

FirstName, SecondName

=CONCATENATE("'",A1,"', ",B1,"'")

Will give you

'FirstName', 'SecondName'

Then wrap in square brackets

['FirstName', 'SecondName']

If your names are in a list even better just do:

=CONCATENATE("'",A1,"', ")

Then copy the formula across all rows, so you have something like:

'FirstName',
'SecondName',
'ThirdName',

Remove the last comma and wrap in square brackets again

['FirstName',
'SecondName',
'ThirdName']

Add this to your page

var names = ['FirstName',
'SecondName',
'ThirdName']
Charles Bryant
  • 995
  • 2
  • 18
  • 30
  • But how to use concatenate in jquery? Can you give me a sample working full examle code for this? – KNB Dec 03 '15 at 15:03
  • I am not sure I really follow what you are asking? If you use concatenate, you will then be able to copy the javascript and put this in your javascript file. If you want javascript to read directly from excel, then this is not possible with out using node.js or a similar server side language. – Charles Bryant Dec 03 '15 at 20:49
  • I am not really sure that this is possible. If it is I imagine it would be more hassle than it is worth the hassle. Your best bet is to use a server based language that can read excel formats, the generate your javascript with them. It may be possible to use Google Sheets to do what you want. – Charles Bryant Dec 04 '15 at 09:03