Results 1 to 10 of 10

Thread: Importing Data From Grid to Ms-Excel in Extjs 3.2

  1. #1
    Sencha User
    Join Date
    Mar 2011
    Location
    Bangalore,india
    Posts
    14

    Default Importing Data From Grid to Ms-Excel in Extjs 3.2

    Hi
    I want to Export data into Excel from Grid using Extjs 3.2.1 and latest browsers. I was able to get work this functionality in Extjs 3.0 and FF4 but not in latest browsers.
    Can anyone help me to solve this.

  2. #2
    Sencha User
    Join Date
    Aug 2010
    Posts
    45

    Default

    Hi, see my answer on http://www.sencha.com/forum/showthre...to-text-format
    or
    http://www.sencha.com/forum/showthre...026#post657026

    I'm curious to your solution in the previous version for FF, can you post the code for that ?
    Grtz

  3. #3
    Sencha User
    Join Date
    Mar 2011
    Location
    Bangalore,india
    Posts
    14

    Default

    Hi,
    Appreciate your efforts for "Importing data to Excel" development .I looked at your code ,I want to ask that will it support Extjs3.2.1 and IE8.
    I am attaching the folder which is working in earlier browsers and Extjs
    .extjs-export-to-excel.zip

  4. #4
    Sencha User
    Join Date
    Aug 2010
    Posts
    45

    Default

    Hi, thanks, i looked at exporter.js before but id didn't work out of the box for Ext 3.3.1, clearly it does with 3.0.0.
    My code works with Ext 3.3.1 and is tested with IE8.

    I'll use the exporter approach tu produce a CSV file and see what it givers in 3.3.1, i keep you informed

    Grtz

  5. #5
    Sencha User
    Join Date
    Mar 2011
    Location
    Bangalore,india
    Posts
    14

    Default

    Hi daddie,
    I checked that your code is working fine with Extjs3.0.0 , 3.1 and IE8 but when i tried it with Extjs 3.2.1 and 3.3.1 it saying that
    " Automation server can't create object".
    This problem is occurring when i trying to create object of ActiveXObject as-
    var xlApp = new ActiveXObject("Excel.Application");

    Can you help me for this.

  6. #6
    Sencha User
    Join Date
    Aug 2010
    Posts
    45

    Default

    Hi, that's very strange since that line has nothing to do with ExtJs or the version it is in.
    Isolate and adapt the code to just make the ActiveX call and test it
    I'm busy with a non ActiveX solution for both IE and FF

    testActiveX.js

    Code:
    if (window.ActiveXObject){ 
           var xlApp = new ActiveXObject("Excel.Application"); 
           xlApp.Visible = true; 
           var xlBook = xlApp.Workbooks.Add(); 
           xlBook.worksheets(1).activate(); 
           var XlSheet = xlBook.activeSheet; 
           xlApp.visible = true; 
           XlSheet.cells(1, 1).value = 'test';
    }

  7. #7
    Sencha User
    Join Date
    Mar 2011
    Location
    Bangalore,india
    Posts
    14

    Default

    Hi,
    Thanks a lot .I got solution this is happening bcz of security measure of Browser. If I will set security low then it works fine.
    I am thinking that this will not be good effort to solve the problem instead using exporter.js will be good that will provide formatting the excel's cells also.
    Give me your views.

  8. #8
    Sencha User
    Join Date
    Aug 2010
    Posts
    45

    Default

    You can do formatting this way too, actually is VBA code you are using so everyting you do in Excel itself should be possible. Exporter.js if fine but doesn't work in IE6 and 7 and you don't realy need it, here is a version that works without ActiveX in FF and IE6 and up. It's much easier to implement but lacks formatting.

    Code:
    bbar : [{
      id : 'grid-excel-button',
      text : 'Export to Excel...',
      handler : function() {
        var xd = toCSV(grid);
        if (Ext.isIE6 || Ext.isIE7 || Ext.isIE8) { //i'm not sure about IE8
           window.clipboardData.setData('Text', xd); //confirmation will be asked
          alert('Now, switch to Excel, position the cursor to where the data are to be inserted and paste the data.');
        } else if (Ext.isSafari || Ext.isSafari2 || Ext.isSafari3){
          //you are on your own here
        } else {
          document.location = 'data:application/vnd.ms-excel;base64,' + Base64.encode(xd);
        }
      }
    }]
    function toCSV(grid) {
      var store = grid.getStore(), xlCol, field, result = '', separator = '';
      for (xlCol = 0; xlCol < store.fields.length; xlCol++) {
        field = store.fields.itemAt(xlCol).name;
        result += separator+'"'+field+'"';
        separator = '\t';
      }
      result += '\r';
      store.each(function(record) {
        separator = '';
        for (xlCol = 0; xlCol < record.fields.length; xlCol++) {
          var field = store.fields.itemAt(xlCol).name;
          //you could make a difference for other types than text
          result += separator+'"'+record.get(field)+'"';
          separator = '\t';
        }
        result += '\r';
      });
      return result;
    }

  9. #9
    Sencha User
    Join Date
    Mar 2011
    Location
    Bangalore,india
    Posts
    14

    Default

    Hi,
    Thanks for your help. Here I want to ask 1 thing as u told after getting values in csv format , have to switch to Excel and point to position to paste the data. In this case I need to create Excel object by ActiveXObject or by workbook(exporter.js). In case of ActiveXObject it will be again security measurements. Can you tell me
    what to do.

  10. #10
    Sencha User
    Join Date
    Aug 2010
    Posts
    45

    Default

    In IE6 and IE7 (don't know about IE8) but not in IE9 the data uri won't work, so the sollution of exporter.js and mine with CSV won't work. Instead for these versions, for my solution, the user just has to start Excel manually, position the cursor and press paste. For the other browser this should work just like exporter.js but without formatting (could be added in theory).
    This has advantages too since you can paste at any location you want instead of having a worksheet created and filled for you. This uses the clipboard and the user will have to give his permission but no ActiveX is needed (haven't tested it yet without ActiveX desactivated though)

    BTW removed the line var w = window.open(....), isn't necessarry

    Grtz

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •