需求时想根据填充的数据行数来复制填充对应行数的公式列数据,表格要做保护,用了isProtected
问题是不用isProtected使用getUsedRange能获取到对应的数据行数
如上图所示,填充了很多行,但是使用curSheet.getUsedRange(GC.Spread.Sheets.UsedRangeType.all)获取时,rowCount变成-1;各位大佬有什么方法能获取到正确的填充数据行数吗?
代码如下,求大佬解惑
if(Array.isArray(sheetNames) && sheetNames.length){
for (let i = 0; i < sheetNames.length; i++) {
let curSheet = spread.getSheetFromName(sheetNames[i])
if(curSheet){
curSheet.options.protectionOptions = protectOption
curSheet.options.isProtected = false;
console.log("isProtected",curSheet.options.isProtected,curSheet.options.protectionOptions)
console.log("curSheet>>>>>>",sheetNames[i],curSheet)
let curRange = curSheet.getUsedRange(GC.Spread.Sheets.UsedRangeType.all)
let colCount = curRange.colCount
let rowCount = curRange.rowCount
console.log("Count",colCount,rowCount,curRange)
for (let j = 0; j < colCount; j++) {
console.log(formula,formula.includes(j),j)
if(!formula.includes(j+1)){
// curSheet.setStyle(-1,j,styleLock,GC.Spread.Sheets.SheetArea.viewport)
// curSheet.setStyle(-1,j,unLockStyle,GC.Spread.Sheets.SheetArea.viewport)
const cell = curSheet.getValue(1, j);
console.log(formula[i],2,j,cell)
// console.log(curSheet.getValue(1, 3),curSheet.getValue(2, 3))
if(cell){
let curFormal = curSheet.getFormula(1,j,GC.Spread.Sheets.SheetArea.viewport)
console.log("cellFormal",curFormal)
curSheet.setFormula(1,j,curFormal)
console.log("cellFormal",curFormal)
// curSheet.setStyle(1,j,styleLock,GC.Spread.Sheets.SheetArea.viewport)
for (let k = 2; k < rowCount; k++) {
curSheet.copyTo(1,j,k,j,1,1,GC.Spread.Sheets.CopyToOptions.all)
console.log("copy getValue>>>>>>>>>>>>>>",curSheet.getValue(k,j))
// let curStyle = curSheet.getStyle(k,j,GC.Spread.Sheets.SheetArea.viewport)
// curStyle.locked = true;
// curStyle.backColor = '#F4F8EB';
// curSheet.getCell(k,j).locked(true)
}
curSheet.setStyle(-1,j,styleLock,GC.Spread.Sheets.SheetArea.viewport)
}else{
console.log(j+"列非单元格无数据+++++++++++++++++++++++++++++++++++++++++++++++++")
}
}else{
console.log(j+"列非公式列+++++++++++++++++++++++++++++++++++++++++++++++++")
// curSheet.setStyle(-1,j,unLockStyle,GC.Spread.Sheets.SheetArea.viewport)
}
}
curSheet.options.isProtected = true;
}
}
}
|
-
|