Skip to content

Commit

Permalink
According to rstudio#418, improve buttons.html5.min.js. This builds o…
Browse files Browse the repository at this point in the history
…n commit 6b56d58 and process the col/row span information to merge the cells at the excel output  via the function excelHtml5
  • Loading branch information
mtyszler committed Jan 6, 2020
1 parent 6b56d58 commit f7742c0
Showing 1 changed file with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -444,16 +444,114 @@
p.title && (r([p.title], g), k(g, /*d.header.length*/ d.header[d.header.length - 1].length - 1));
p.messageTop && (r([p.messageTop],
g), k(g, /*d.header.length*/ d.header[d.header.length - 1].length - 1));

/* ----- BEGIN added Code ----- */
//c.header && (r(d.header, g), i("row:last c", e).attr("s", "2"));

if(c.header){
row_start_headers = g;
for (o = 0; o < d.header.length; o++){
r(d.header[o], g);
i("row:last c", e).attr("s", "2");
}
}

// process merged cells:
var mgCnt = 0;
var merges=[];
if (c.header) {
//for each header row
for(o=0; o < d.header.length; o++)
{
//for each column (cell) in the row
for(oj=0; oj<d.header[o].length; oj++)
{
//look for a non-colspan/rowspan cell
if(d.header[o][oj] != "")
{
var startRow = o;
var startCol = oj;
var endRow = o;
var endCol = oj;

//lookahead
if(oj+1 < d.header[o].length){
if(d.header[o][oj+1] == "") //is the cell to the right a colspan?
{

startCol = oj;
endCol = oj+1;

//get to the last column in the colspan
while(endCol < d.header[o].length && d.header[o][endCol] == "")
{
endCol++;
}
endCol--;
}
}

if(o+1 < d.header.length) {
if(d.header[o+1][oj] == "") //is the cell below a rowspan?
{

startRow = o;
endRow = o+1;

//get to the last row in the rowspan
while(endRow < d.header.length && d.header[endRow][oj] == "")
{
endRow++;
}
}
}

//create and store merge ranges
//if endCol or endRow show movement
if(startRow != endRow || startCol != endCol)
{
sC = z(startCol); //convert startCol to excel column letter
sR = startRow+1+row_start_headers; // actual row to be merged needs to take into account 0 index and current row (g)
eC = z(endCol); //convert endCol to excel column letter
eR = endRow+row_start_headers; // actual row to be merged needs to take into account 0 index and current row (g)

merges[mgCnt] = sC+""+sR; //start of range

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;
}

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


if (mgCnt > 0) {
//add each merge range as a child
var oc = i("mergeCells", e);
for(o=0;o<mgCnt;o++)
{

oc[0].appendChild(q(e, "mergeCell", {
attr: {
ref: merges[o]
}
}));
oc.attr("count", parseFloat(oc.attr("count")) + 1);
}
}

/*END added code*/
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"));
Expand Down

0 comments on commit f7742c0

Please sign in to comment.