Page 20 of 30 FirstFirst ... 101819202122 ... LastLast
Results 191 to 200 of 296

Thread: GridPanel directly to Excel.

  1. #191
    Ext User
    Join Date
    Jul 2008
    Posts
    60
    Vote Rating
    0
      0  

    Default

    Emredagli,
    Can u please tell me How did you add Group Headers to the SpreadSheet to work.

    Thank you,
    Tina.

  2. #192
    Sencha User TopKatz's Avatar
    Join Date
    Mar 2007
    Posts
    340
    Vote Rating
    2
      0  

    Default

    This working in 3.x. However OO does not like the output.

  3. #193
    Sencha User emredagli's Avatar
    Join Date
    Jun 2008
    Posts
    301
    Vote Rating
    2
      0  

    Default

    tinakonda,
    I could not remember well,
    Sorry for that,
    I modified Mr. Animal's code. So I am sending the my code. But please it is modified version for my requirements. It will not work if you try to use directly.
    Code:
    Ext.override(Ext.grid.GridPanel, {
        getExcelXml: function(includeHidden, title) {
            var worksheet = this.createWorksheet(includeHidden, title);
            var totalWidth = this.getColumnModel().getTotalWidth(includeHidden);
            return '<?xml version="1.0" encoding="utf-8"?>' +
                '<ss:Workbook xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:o="urn:schemas-microsoft-com:office:office">' +
                '<o:DocumentProperties><o:Title>' + title + '</o:Title></o:DocumentProperties>' +
                '<ss:ExcelWorkbook>' +
                    '<ss:WindowHeight>' + worksheet.height + '</ss:WindowHeight>' +
                    '<ss:WindowWidth>' + worksheet.width + '</ss:WindowWidth>' +
                    '<ss:ProtectStructure>False</ss:ProtectStructure>' +
                    '<ss:ProtectWindows>False</ss:ProtectWindows>' +
                '</ss:ExcelWorkbook>' +
                '<ss:Styles>' +
                    '<ss:Style ss:ID="Default">' +
                        '<ss:Alignment ss:Vertical="Top" ss:WrapText="1" />' +
                        '<ss:Font ss:FontName="arial" ss:Size="10" />' +
                        '<ss:Borders>' +
                            '<ss:Border ss:Color="#e4e4e4" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Top" />' +
                            '<ss:Border ss:Color="#e4e4e4" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Bottom" />' +
                            '<ss:Border ss:Color="#e4e4e4" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Left" />' +
                            '<ss:Border ss:Color="#e4e4e4" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Right" />' +
                        '</ss:Borders>' +
                        '<ss:Interior />' +
                        '<ss:NumberFormat />' +
                        '<ss:Protection />' +
                    '</ss:Style>' +
                    '<ss:Style ss:ID="title">' +
                        '<ss:Borders />' +
                        '<ss:Font />' +
                        '<ss:Alignment ss:WrapText="1" ss:Vertical="Center" ss:Horizontal="Center" />' +
                        '<ss:NumberFormat ss:Format="@" />' +
                    '</ss:Style>' +
                    '<ss:Style ss:ID="groupheadercell">' +
                        '<ss:Font ss:Italic="1" ss:Bold="1" ss:Size="10" />' +
                        '<ss:Alignment ss:WrapText="1"/>' +
                        '<ss:Interior ss:Pattern="Solid" ss:Color="#33FF99" />' +
                    '</ss:Style>' +                
                    '<ss:Style ss:ID="headercell">' +
                        '<ss:Font ss:Bold="1" ss:Size="10" />' +
                        '<ss:Alignment ss:WrapText="1" ss:Horizontal="Center" />' +
                        '<ss:Interior ss:Pattern="Solid" ss:Color="#A3C9F1" />' +
                    '</ss:Style>' +
                    '<ss:Style ss:ID="even">' +
                        '<ss:Interior ss:Pattern="Solid" ss:Color="#FFFFCC" />' +
                    '</ss:Style>' +
                    '<ss:Style ss:Parent="even" ss:ID="evendate">' +
                        '<ss:NumberFormat ss:Format="[ENG][$-409]dd\-mmm\-yyyy;@" />' +
                    '</ss:Style>' +
                    '<ss:Style ss:Parent="even" ss:ID="evenint">' +
                        '<ss:NumberFormat ss:Format="0" />' +
                    '</ss:Style>' +
                    '<ss:Style ss:Parent="even" ss:ID="evenfloat">' +
                        '<ss:NumberFormat ss:Format="0.00" />' +
                    '</ss:Style>' + 
                    '<ss:Style ss:Parent="even" ss:ID="evenmoney">' +
                        '<ss:Alignment ss:Horizontal="Right" />' +
                    '</ss:Style>' +                 
                    '<ss:Style ss:ID="odd">' +
                        '<ss:Interior ss:Pattern="Solid" ss:Color="#FFFFFF" />' +
                    '</ss:Style>' +
                    '<ss:Style ss:Parent="odd" ss:ID="odddate">' +
                        '<ss:NumberFormat ss:Format="[ENG][$-409]dd\-mmm\-yyyy;@" />' +
                    '</ss:Style>' +
                    '<ss:Style ss:Parent="odd" ss:ID="oddint">' +
                        '<ss:NumberFormat ss:Format="0" />' +
                    '</ss:Style>' +
                    '<ss:Style ss:Parent="odd" ss:ID="oddfloat">' +
                        '<ss:NumberFormat ss:Format="0.00" />' +
                    '</ss:Style>' +
                    '<ss:Style ss:Parent="odd" ss:ID="oddmoney">' +
                        '<ss:Alignment ss:Horizontal="Right" />' +
                    '</ss:Style>' +    
                    '<ss:Style ss:ID="right">' +
                        '<ss:Alignment ss:Horizontal="Right" />' +
                    '</ss:Style>' +    
                    '<ss:Style ss:Parent="right" ss:ID="rightGroupSummary">' +  
                       '<ss:Interior ss:Pattern="Solid" ss:Color="#CCFFFF" />' +
                    '</ss:Style>' +        
                    '<ss:Style ss:Parent="right" ss:ID="rightTotalSummary">' + 
                       '<ss:Interior ss:Pattern="Solid" ss:Color="#ADD8E6" />' +
                    '</ss:Style>' +                    
                    '<ss:Style ss:ID="left">' +
                        '<ss:Alignment ss:Horizontal="Left" />' +
                    '</ss:Style>' +    
                    '<ss:Style ss:Parent="left" ss:ID="leftGroupSummary">' +
                       '<ss:Interior ss:Pattern="Solid" ss:Color="#CCFFFF" />' +
                    '</ss:Style>' +        
                    '<ss:Style ss:Parent="left" ss:ID="leftTotalSummary">' +
                       '<ss:Interior ss:Pattern="Solid" ss:Color="#ADD8E6" />' +
                    '</ss:Style>' +                    
                '</ss:Styles>' +
                worksheet.xml +
                '</ss:Workbook>';
        },
    
        createWorksheet: function(includeHidden, title) {
    
    //      Calculate cell data types and extra class names which affect formatting
            var cellType = [];
            var cellTypeClass = [];
            var cm = this.getColumnModel();
            var totalWidthInPixels = 0;
            var colXml = '';
            var headerXml = '';
            var visibleColumnCount = 0;
            var i;
            var columnID;
            for (i = 0; i < cm.getColumnCount(); i++) {
                if (includeHidden || !cm.isHidden(i)) {
                    var w = cm.getColumnWidth(i);
                    totalWidthInPixels += w;
                    colXml += '<ss:Column ss:AutoFitWidth="1" ss:Width="' + w + '" />';
                    headerXml += '<ss:Cell ss:StyleID="headercell">' +
                        '<ss:Data ss:Type="String">' + cm.getColumnHeader(i) + '</ss:Data>' +
                        '<ss:NamedCell ss:Name="Print_Titles" /></ss:Cell>';
                    //var fld = this.store.recordType.prototype.fields.get(cm.getDataIndex(i));
                    columnID = cm.getColumnId(i);
                    var fld = cm.getColumnById(columnID).alignType; 
                    switch(fld) {
                        case "right":
                            cellType[i] ="String";
                            cellTypeClass[i] ="money";
                            break;
                        default:
                            cellType[i] ="String";
                            cellTypeClass[i] ="";
                            break;
                    }
                    visibleColumnCount ++;
                }
            } 
            
    
            var result = {
                height: 9000,
                width: Math.floor(totalWidthInPixels * 30) + 50
            };
    //      Counting group filed:
            var groupFieldCount = 0;
            var groupField = this.store.groupField;
            var previousGroupFieldValue = '';        
            for (i = 0, it = this.store.data.items, l = it.length; i < l; i++) {
                r = it[i].data;
                if (previousGroupFieldValue != r[groupField])
                {
                    groupFieldCount++;
                    previousGroupFieldValue = r[groupField];
                }
            }
    //      Generate worksheet header details.
            var t = '<ss:Worksheet ss:Name="' + title + '">' +
                '<ss:Names>' +
                    '<ss:NamedRange ss:Name="Print_Titles" ss:RefersTo="=\'' + title + '\'!R1:R2" />' +
                '</ss:Names>' +
                '<ss:Table x:FullRows="1" x:FullColumns="1"' +
                    ' ss:ExpandedColumnCount="' + visibleColumnCount +
                    '" ss:ExpandedRowCount="' + (this.store.getCount() + 2 + 2 * groupFieldCount + 1) + '">' +
                    colXml +
                    '<ss:Row ss:Height="38">' +
                        '<ss:Cell ss:StyleID="title" ss:MergeAcross="' + (visibleColumnCount - 1) + '">' +
                          '<ss:Data xmlns:html="http://www.w3.org/TR/REC-html40" ss:Type="String">' +
                            '<html:B><html:U><html:Font html:Size="15">' + title +
                            '</html:Font></html:U></html:B></ss:Data><ss:NamedCell ss:Name="Print_Titles" />' +
                        '</ss:Cell>' +
                    '</ss:Row>' +
                    '<ss:Row ss:AutoFitHeight="1">' +
                    headerXml + 
                    '</ss:Row>';
    
    //      Generate the data rows from the data in the Store
    
            var groupFieldIndex = cm.findColumnIndex(groupField);
            previousGroupFieldValue = '';
            var groupCount = 0;
            for (i = 0, it = this.store.data.items, l = it.length; i < l; i++) {
                
                var cellClass = (i & 1) ? 'odd' : 'even';
                r = it[i].data;
                
                if (previousGroupFieldValue != r[groupField] && previousGroupFieldValue !='')
                {
                    t += '<ss:Row>';
                    for (var j = 0; j < cm.getColumnCount(); j++) {
                        if (groupSummaryValues[j] != null)
                        {
                            columnID = cm.getColumnId(j);
                            var fld = cm.getColumnById(columnID).alignType;
                            t += '<ss:Cell'+ (fld == 'right' ? ' ss:StyleID="rightGroupSummary"' : ' ss:StyleID="leftGroupSummary"') +'>';
                            t += '<ss:Data ss:Type="String">';
                            t += groupSummaryValues[j][groupCount];
                            t +='</ss:Data></ss:Cell>';
                        }
                    }
                    t += '</ss:Row>';
                    groupCount++;
                }
                
                if (previousGroupFieldValue != r[groupField])
                {
                    var v = r[groupField];
    
                    t += '<ss:Row>' +
                        '<ss:Cell ss:StyleID="groupheadercell" ss:MergeAcross="' + (visibleColumnCount - 1) + '">' +
                          '<ss:Data ss:Type="String">' +
                            groupValues[groupCount] +
                            '</ss:Data>' + '</ss:Cell>' + '</ss:Row>';
            
                    previousGroupFieldValue = r[groupField];
                }
                
    
                t += '<ss:Row>';
                for (var j = 0; j < cm.getColumnCount(); j++) {
                    if (includeHidden || !cm.isHidden(j)) {
                        var v = r[cm.getDataIndex(j)];
                        t += '<ss:Cell ss:StyleID="' + cellClass + cellTypeClass[j] + '"><ss:Data ss:Type="String">';
                        t += rendererValues[j][i]; //cm.getRenderer(j)(v);
                        t +='</ss:Data></ss:Cell>';
                    }
                }
                t += '</ss:Row>';
            }
    
            //   Son Group Summary
            t += '<ss:Row>';
            for (var j = 0; j < cm.getColumnCount(); j++) {
                if (groupSummaryValues[j] != null)
                {
                    columnID = cm.getColumnId(j);
                    var fld = cm.getColumnById(columnID).alignType;
                    t += '<ss:Cell'+ (fld == 'right' ? ' ss:StyleID="rightGroupSummary"' : ' ss:StyleID="leftGroupSummary"') +'>';
                    t += '<ss:Data ss:Type="String">';
                    t += groupSummaryValues[j][groupCount];
                    t +='</ss:Data></ss:Cell>';
                }
            }
            t += '</ss:Row>';
                    
            //  Total Summary
            t += '<ss:Row>';
            for (var j = 0; j < cm.getColumnCount(); j++) {
                if (summaryTotalValues[j] != null)
                {
                    columnID = cm.getColumnId(j);
                    var fld = cm.getColumnById(columnID).alignType; 
                     
                    t += '<ss:Cell'+ (fld == 'right' ? ' ss:StyleID="rightTotalSummary"' : ' ss:StyleID="leftTotalSummary"') +'>';
                    t += '<ss:Data ss:Type="String">';
                    t += summaryTotalValues[j];
                    t +='</ss:Data></ss:Cell>';
                }
            }
            t += '</ss:Row>';
            
            result.xml = t + '</ss:Table>' +
                '<x:WorksheetOptions>' +
                    '<x:PageSetup>' +
                        '<x:Layout x:CenterHorizontal="1" x:Orientation="Landscape" />' +
                        '<x:Footer x:Data="Page &amp;P of &amp;N" x:Margin="0.5" />' +
                        '<x:PageMargins x:Top="0.5" x:Right="0.5" x:Left="0.5" x:Bottom="0.8" />' +
                    '</x:PageSetup>' +
                    '<x:FitToPage />' +
                    '<x:Print>' +
                        '<x:PrintErrors>Blank</x:PrintErrors>' +
                        '<x:FitWidth>1</x:FitWidth>' +
                        '<x:FitHeight>32767</x:FitHeight>' +
                        '<x:ValidPrinterInfo />' +
                        '<x:VerticalResolution>600</x:VerticalResolution>' +
                    '</x:Print>' +
                    '<x:Selected />' +
                    '<x:DoNotDisplayGridlines />' +
                    '<x:ProtectObjects>False</x:ProtectObjects>' +
                    '<x:ProtectScenarios>False</x:ProtectScenarios>' +
                '</x:WorksheetOptions>' +
            '</ss:Worksheet>';
            return result;
        }
    });
    Code:
    function post_to_url(path, params, method) {
        method = method || "post"; // Set method to post by default, if not specified.
    
        // The rest of this code assumes you are not using a library.
        // It can be made less wordy if you use one.
        var form = document.createElement("form");
        form.setAttribute("method", method);
        form.setAttribute("action", path);
    
        for(var i=0; i<params.length; i++) {
            var hiddenField = document.createElement("input");
            hiddenField.setAttribute("type", "hidden");
            hiddenField.setAttribute("name", params[i].name);
            hiddenField.setAttribute("value", params[i].value);
    
            form.appendChild(hiddenField);
        }
    
        document.body.appendChild(form);    // Not entirely sure if this is necessary
        form.submit();
    }
    
    var excelFileCounter = 1;
    
    function exportExcell() {
    
        var dataURL = 'CommonPages/Export.aspx';
    
        params =[{
            name: 'Data',
            value: resultGrid.getExcelXml(false,'Result '+resultsToolClass.selectedToolID)
        },{
            name: 'FileName',
            value: 'WISECTS-Results-'+excelFileCounter+'.xls'
        },{
            name: 'ContentType',
            value: 'application/vnd.ms-excel'
        }];
        
        excelFileCounter++;
        
        post_to_url(dataURL, params, 'post');
    }

  4. #194
    Sencha User emredagli's Avatar
    Join Date
    Jun 2008
    Posts
    301
    Vote Rating
    2
      0  

    Default

    I forgot to add attachment:
    This is the output of my code. Excel file.
    Attached Files Attached Files

  5. #195
    Ext User
    Join Date
    Feb 2009
    Posts
    60
    Vote Rating
    0
      0  

    Default

    Hey - in the code on p1 - there seems to be a bug:

    Code:
    Generate the data rows from the data in the Store
            for (var i = 0, it = this.store.data.items, l = it.length; i < l; i++) {
                t += '<ss:Row>';
                var cellClass = (i & 1) ? 'odd' : 'even';
                r = it[i].data;
                var k = 0;
                for (var j = 0; j < cm.getColumnCount(); j++) {
                    if (includeHidden || !cm.isHidden(j)) {
                        var v = r[cm.getDataIndex(j)];
                        t += '<ss:Cell ss:StyleID="' + cellClass + cellTypeClass[k] + '"><ss:Data ss:Type="' + cellType[j] + '">';
                            if (cellType[k] == 'DateTime') {
                                t += v.format('Y-m-d');
                            } else {
                                t += v;
                            }
                        t +='</ss:Data></ss:Cell>';
                        k++;
                    }
                }
                t += '</ss:Row>';
            }
    Shouldn't that be:

    Code:
     t += '<ss:Cell ss:StyleID="' + cellClass + cellTypeClass[k] + '"><ss:Data ss:Type="' + cellType[k] + '">';
    ?

    w://
    --------------------------------------------

    collaborate & fix: http://jsbin.com/
    verify: http://www.jslint.com/
    beutify: http://jsbeautifier.org/

  6. #196
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,608
    Vote Rating
    59
      0  

    Default

    Indeed it should be. Well spotted. I've edited the post to match your fix. Thanks.

  7. #197
    Ext User
    Join Date
    Feb 2009
    Posts
    60
    Vote Rating
    0
      0  

    Default

    Just wondering if anyone had figured out a way to do grouping on the data?

    w://
    --------------------------------------------

    collaborate & fix: http://jsbin.com/
    verify: http://www.jslint.com/
    beutify: http://jsbeautifier.org/

  8. #198
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,608
    Vote Rating
    59
      0  

    Default

    It's certainly possible.

    You'd just have to put a value change test where you loop through the store, and on change, insert a <ss:Row><ss:Cell colspan="?"> with some data in it.

    I think it uses colspan. Check the docs I linked to ni the first post.

  9. #199
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,608
    Vote Rating
    59
      0  

    Default

    http://msdn.microsoft.com/en-us/libr...ffice.10).aspx

    it's ss:MergeAcross that you'd use to do a colspan.

  10. #200
    Sencha User Dumas's Avatar
    Join Date
    Dec 2008
    Location
    Vienna, Austria
    Posts
    589
    Vote Rating
    10
      0  

    Default

    Hi!

    I'm allways getting that Ext.LinkButton is not a constructor, any ideas what's wrong?

    thx
    Dumas

Page 20 of 30 FirstFirst ... 101819202122 ... LastLast

Posting Permissions

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