Skip to content

Commit

Permalink
According to rstudio#418, improve dataTables.buttons.min.js, mimickin…
Browse files Browse the repository at this point in the history
  • Loading branch information
mtyszler committed Jan 3, 2020
1 parent 3178277 commit f80c7da
Showing 1 changed file with 120 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,129 @@
p.title && (r([p.title], g), k(g, d.header.length - 1));
p.messageTop && (r([p.messageTop],
g), k(g, d.header.length - 1));
c.header && (r(d.header, g), i("row:last c", e).attr("s", "2"));
/* BEGIN ADD */
//c.header && (r(d.header, g), i("row:last c", e).attr("s", "2"));
var mgCnt = 0;
var merges=[];
if (c.header) {
//for each header row
for(i=0; i < d.header.length; i++)
{
//for each column (cell) in the row
for(j=0; j<d.header[i].length; j++)
{
//look for a non-colspan/rowspan cell
if(d.header[i][j] != "" && d.header[i][j] != "")
{
var startRow = i;
var startCol = j;
var endRow = i;
var endCol = j;

//console.log(i+":"+j+"="+b.header[i][j]);

//lookahead
if(j+1 < d.header[i].length)
if(d.header[i][j+1] == "") //is the cell to the right a colspan?
{
//console.log("cspan start:"+b.header[i][j]);
startCol = j;
endCol = j+1;

//get to the last column in the colspan
while(endCol < d.header[i].length &&d.header[i][endCol] == "")
{
//b.header[i][endCol] = ""; //Use if cspan is a special char/sequence
endCol++;
}
endCol--;
}

if(i+1 < d.header.length)
if(d.header[i+1][j] == "") //is the cell below a rowspan?
{
//console.log("rspan start:"+b.header[i][j]);
startRow = i;
endRow = i+1;

//get to the last row in the rowspan
while(endRow < d.header.length && d.header[endRow][j] == "")
{
//b.header[endRow][j] = ""; //Use if rowspan is a special char/sequence
endRow++;
}
}

//create and store merge ranges
//if endCol or endRow show movement
if(startRow != endRow || startCol != endCol)
{
sC = colLetter(startCol); //convert startCol to excel column letter
sR = startRow+1;
eC = colLetter(endCol); //conver endCol to excel column letter
eR = endRow;

//console.log("sC="+sC);
merges[mgCnt] = sC+""+sR; //start of range

//console.log("endrow > startrow="+endRow+">"+startRow);
//console.log("endCol > startcol="+endCol+">"+startCol);

if(endCol > startCol) //end column
merges[mgCnt] = merges[mgCnt] + ":" + eC;
else
merges[mgCnt] = merges[mgCnt] + ":" + sC;

if(endRow > startRow) //end row
merges[mgCnt] = merges[mgCnt] + eR;
else
merges[mgCnt] = merges[mgCnt] + sR;

//console.log("merges[mgCnt]="+merges[mgCnt]);

mgCnt++; //increment number of merge ranges
}
}
}
}

//add multiple headers
for (i = 0; i < b.header.length; i++){
d(b.header[i], e);
g("row c", f).attr("s", "2"); //maybe should be outside the loop?
}
}
/* END ADD */
for (var o = 0, u = d.body.length; o < u; o++) r(d.body[o], g);
c.footer && d.footer && (r(d.footer, g), i("row:last c", e).attr("s", "2"));
p.messageBottom && (r([p.messageBottom], g), k(g, d.header.length - 1));

/* BEGIN ADD */
//if we have merges
if (mgCnt > 0)
{
//create a mergeCells section
z = o(f, "mergeCells", {
attr: {
count: mgCnt,
}
});

//add each merge range as a child
for(i=0;i<mgCnt;i++)
{
n = o(f, "mergeCell", {
attr: {
ref: merges[i]
}
});
z.appendChild(n);
}
}
if(z.children)
g("worksheet", f).append(z) //add to the worksheet

/*END ADD */
r = q(e, "cols");
i("worksheet", e).prepend(r);
k = 0;
Expand Down

0 comments on commit f80c7da

Please sign in to comment.