2

good, i am using this code to link http://brianhann.com/exporting-spreadsheets-from-ui-grid/ export to excel ui-grid from a table, but I skip this mistake, I pass what happens to me. I error occurs in the code where it says:

$rows.forEach(function (row, ri) {
  ri +=1;
  $scope.gridApi.grid.columns.forEach(function (col, ci) {
    var loc = XLSX.utils.encode_cell({r: ri, c: ci});
    sheet[loc] = {
      v: row[ci].value,
      t: 's'
    };
    endLoc = loc;
  });

Regards, and thank you very much.

The code of controller is:

$scope.exportXLSX = function(){
var data = [
  [] // header row
];

var rows = uiGridExporterService.getData($scope.gridApi.grid, uiGridExporterConstants.VISIBLE, uiGridExporterConstants.VISIBLE);

var sheet = {};

$scope.gridApi.grid.columns.forEach(function (col, i) {
  if (col.visible) {
    var loc = XLSX.utils.encode_cell({r: 0, c: i})
    sheet[loc] = {
      v: col.displayName
    };
  }
});

var endLoc;
rows.forEach(function (row, ri) {
  ri +=1;
  $scope.gridApi.grid.columns.forEach(function (col, ci) {
    var loc = XLSX.utils.encode_cell({r: ri, c: ci});
    sheet[loc] = {
      v: row[ci].value,
      t: 's'
    };
    endLoc = loc;
  });
});
sheet['!ref'] = XLSX.utils.encode_range({ s: 'A1', e: endLoc });

var workbook = {
  SheetNames: ['Sheet1'],
  Sheets: {
    Sheet1: sheet
  }
};

var wopts = { bookType: 'xlsx', bookSST: false, type: 'binary' };
var wbout = XLSX.write(workbook, wopts);

saveAs(new Blob([s2ab(wbout)], {type: ""}), "test.xlsx");

};

error

1 Answer 1

1

I suggest you using alasql

https://github.com/agershun/alasql

With a code like that:

    $scope.exportMyData = function() {

        alasql('SELECT c1 AS columnA, c2 AS columnB, c3 AS columnC INTO XLSX("data.xlsx",{headers:true}) FROM ?',
          [$scope.myDataSource]);
    }

And in the HTML

        <button type="button" class="btn btn-primary" ng-click="exportMyData()"> Export </button>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.