Merged cells display in WPS office but not displaying in Microsoft office excel

Merged cells display in WPS office but not displaying in Microsoft office excel

KakshKaksh Posts: 1Questions: 1Answers: 0

Merged cells display in WPS office but not displaying in Microsoft office excel, I have use following customize function for the same.

customize: function ( xlsx ){
                    var sheet = xlsx.xl.worksheets['sheet1.xml'];
                    var colRange = sheet.getElementsByTagName('col').length - 1;
                    //var colRange = createCellPos( lastCol ) + '1';
                    var numrows = 3;
                    var clR = $('row', sheet);
 
                    //update Row
                    clR.each(function () {
                        var attr = $(this).attr('r');
                        var ind = parseInt(attr);
                        ind = ind + numrows;
                        $(this).attr("r",ind);
                    });
 
                    // Create row before data
                    $('row c ', sheet).each(function () {
                        var attr = $(this).attr('r');
                        var pre = attr.substring(0, 1);
                        var ind = parseInt(attr.substring(1, attr.length));
                        ind = ind + numrows;
                        $(this).attr("r", pre + ind);
                    });
 
                    function Addrow(index,data, colRange, sheet) {
                        msg='<row r="'+index+'">'
                        for(i=0;i<data.length;i++){
                            var key=data[i].key;
                            var value=data[i].value;
                            var style=data[i].style;
                            mergeCells( index, colRange, sheet );
                            msg += '<c t="inlineStr" s="'+ style +'" r="' + key + index + '">';
                            msg += '<is>';
                            msg +=  '<t>'+value+'</t>';
                            msg+=  '</is>';
                            msg+='</c>';
                        }
                        msg += '</row>';
                        return msg;
                    }
 
                    var mergeCells = function ( row, colspan, sheet ) {
                        var mergeCells = $('mergeCells', sheet);
 
                        mergeCells[0].appendChild( _createNode( sheet, 'mergeCell', {
                            attr: {
                                ref: 'A'+row+':'+createCellPos(colspan)+row
                            }
                        } ) );
                        //mergeCells.attr( 'count', mergeCells.attr( 'count' )+1 );
                        //$('row:eq('+(row-1)+') c', sheet).attr( 's', '51' ); // centre
                    };
 
                    function createCellPos( n ){
                        var ordA = 'A'.charCodeAt(0);
                        var ordZ = 'Z'.charCodeAt(0);
                        var len = ordZ - ordA + 1;
                        var s = "";
                      
                        while( n >= 0 ) {
                            s = String.fromCharCode(n % len + ordA) + s;
                            n = Math.floor(n / len) - 1;
                        }
                      
                        return s;
                    }
                    function _createNode( doc, nodeName, opts ) {
                        var tempNode = doc.createElement( nodeName );
 
                        if ( opts ) {
                            if ( opts.attr ) {
                                $(tempNode).attr( opts.attr );
                            }
 
                            if ( opts.children ) {
                                $.each( opts.children, function ( key, value ) {
                                    tempNode.appendChild( value );
                                } );
                            }
 
                            if ( opts.text !== null && opts.text !== undefined ) {
                                tempNode.appendChild( doc.createTextNode( opts.text ) );
                            }
                        }
                        return tempNode;
                    }
 
                    //insert
                    var r1 = Addrow(1, [{ key: 'A', value: '', style: '51' }], colRange, sheet);
                    var r2 = Addrow(2, [{ key: 'A', value: '', style: '51' }], colRange, sheet);
                    var r3 = Addrow(3, [{ key: 'A', value: '', style: '51' }], colRange, sheet);
 
                    sheet.childNodes[0].childNodes[1].innerHTML = r1 + r2+ r3+ sheet.childNodes[0].childNodes[1].innerHTML;
                }
            }

Answers

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.