spreadjs 复制单元格样式
/**
* @param {起始行} a
* @param {起始列} b
* @param {复制到行} c
* @param {复制到列} d
* @param {复制多少行} e
* @param {复制多少列} f
* @param {添加行循环次数} g
* @param {要复制的sheet页行} copyA
* @param {要复制的sheet页列} copyB
* @param {要复制标签页} copySheet
* @param {复制到标签页} toSheet
* @param {spread} spread
*/
function copysty(a, b, c, d, e, f, g,copyA,copyB,copySheet,toSheet,spread)
{
var sheetto = spread.getSheet(toSheet);
var sheetcopy = spread.getSheet(copySheet);
for (var i = 0; i < g; i++) {
sheetto.addRows(c,e);
var selectionRange = sheetcopy.getRange(copyA,copyB,e,f);
fromRange = selectionRange;
fromSheet = sheetcopy;
sheetto.isPaintSuspended(true);
var toRange = sheetto.getRange(c,d,e,f);
//toRange biger than fromRange
if (fromRange.rowCount > toRange.rowCount) {
toRange.rowCount = fromRange.rowCount;
}
if (fromRange.colCount > toRange.colCount) {
toRange.colCount = fromRange.colCount;
}
//toRange must in Sheet
if (toRange.row + toRange.rowCount > sheetto.getRowCount()){
toRange.rowCount = sheetto.getRowCount() - toRange.row;
}
if (toRange.col + toRange.colCount > sheetto.getColumnCount()) {
toRange.colCount = sheetto.getColumnCount() - toRange.col;
}
var rowStep = fromRange.rowCount, colStep = fromRange.colCount;
var endRow = toRange.row + toRange.rowCount - 1, endCol = toRange.col + toRange.colCount - 1;
// if toRange bigger than fromRange, repeat paint
for (var startRow = toRange.row; startRow <= endRow; startRow = startRow + rowStep) {
for (var startCol = toRange.col; startCol <= endCol; startCol = startCol + colStep) {
var rowCount = startRow + rowStep > endRow + 1 ? endRow - startRow + 1 : rowStep;
var colCount = startCol + colStep > endCol + 1 ? endCol - startCol + 1 : colStep;
// sheet.copyTo(fromRange.row,fromRange.col, startRow, startCol, rowCount, colCount,GC.Spread.Sheets.CopyToOptions.style | GC.Spread.Sheets.CopyToOptions.span);
var fromRanges = new GC.Spread.Sheets.Range(fromRange.row, fromRange.col, rowCount, colCount);
var pastedRange = new GC.Spread.Sheets.Range(startRow, startCol, rowCount, colCount);
spread.commandManager().execute({
cmd: "clipboardPaste",
sheetName: sheetto.name(),
fromSheet: fromSheet,
fromRanges: [fromRanges],
pastedRanges: [pastedRange],
isCutting: false,
clipboardText: "",
pasteOption: GC.Spread.Sheets.ClipboardPasteOptions.all
});
}
}
c += e;
}
}