Home Import from Excel Angular JS
Reply: 0

Import from Excel Angular JS

user2178 Published in June 19, 2018, 2:39 pm

I am trying to import the excel in to the ui-grid. I am trying to use the js xlsx libarary. I can convert the xlsx in to JSON but I am not sure how I can populate the xlsx in to the ui-grid. Below is the ui-grid

$scope.samplesGridOptions = {
enableColumnResizing: true,
enableRowSelection: true,
multiSelect: false,
enableGridMenu: true,
enableCellEditOnFocus: true,
columnDefs: [
    { field: 'externalID', displayName: 'External ID' },
    { field: 'apexLotNum', displayName: 'APEX Lot' },
        field: 'chamberName',
        displayName: 'Chamber Name',
        editType: 'dropdown',
        editableCellTemplate: 'ui-grid/dropdownEditor',
        enableCellEdit: true, editDropdownOptionsArray: $scope.chamberNameList,
        editDropdownIdLabel: 'value',
        editDropdownValueLabel: 'value'
gridMenuCustomItems: [],
onRegisterApi: function (gridApi) {
    $scope.samplesGridAPI = gridApi;
    $scope.samplesGridOptions.data = $scope.virtualSampleList;

I am trying to use the the js-xlsx library below to parse the excel file loaded. But not sure how to push that into the ui-grid, new to javascripting and the libraries

    $scope.ParseExcelDataAndSave = function () {
        var file = $scope.SelectedFileForUpload;
        if (file) {
            var reader = new FileReader();
            reader.onload = function (e) {
                var data = e.target.result;
                var workbook = XLSX.read(data, { type: 'binary' });
                var sheetName = workbook.SheetNames[0];
                var excelData = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[sheetName]);
                var jsonData = JSON.stringify(excelData);
                if (jsonData.length > 0) {
                        **//Here I am not sure how can I populate the ui-grid from the JSON**
                else {
                    $scope.Message = "No data found";
            reader.onerror = function (ex) {

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.311959 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO