spreadjs在选中单元格内查找(SJS-17092)
本帖最后由 Lynn.Dou 于 2023-2-23 10:06 编辑在选中的单元格内使用SearchCondition查找
代码如下:
GC.Spread.Common.CultureManager.culture('zh-cn');
window.parent.GC = GC;
var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss'));
window.parent.spread = spread;
var sheet = spread.getActiveSheet();
sheet.setValue(0,0,30);
sheet.setValue(0,1,1);
sheet.setValue(0,2,25);
sheet.setValue(0,3,9);
sheet.setValue(0,4,15);
sheet.setFormula(3,0,'=LINESPARKLINE(A1:B1:C1:D1:E1,1)')
sheet.setFormula(3,6,'=LINESPARKLINE(B1:C1:D1:E1,1)')
sheet.setFormula(4,4,'=LINESPARKLINE(C1:D1:E1,1)')
var sparkLineHelper = {};
sparkLineHelper.getSparkLineSearchConditin = functiongetSparkLineSearchConditin(){
var searchCondition = new GC.Spread.Sheets.Search.SearchCondition();
searchCondition.searchString='LINESPARKLINE';
searchCondition.searchTarget = GC.Spread.Sheets.Search.SearchFoundFlags.cellFormula;
return searchCondition;
};
sparkLineHelper.doSearch = function doSearch(spread,condition){
return spread.search(condition);
}
sparkLineHelper.searchFromSelections = function searchFromSelections(spread){
var activeSheet = spread.getActiveSheet();
var range = activeSheet.getSelections();
var colStart = range.col;
var colEnd = range.col+range.colCount;
var rowStart = range.row;
var rowEnd = range.row+range.rowCount;
console.log("selections range :");
console.log(range);
var allSparkLines = [];
for(var y = rowStart;y<rowEnd;+y++){
for(var x = colStart;x<colEnd;x++){
var condition = this.getSparkLineSearchConditin();
condition.startSheetIndex = spread.getActiveSheetIndex();
condition.endSheetIndex = spread.getActiveSheetIndex();
condition.columnStart=x;
condition.columnEnd=colEnd-1;
condition.rowStart = y;
condition.rowEnd = rowEnd-1;
// condition.findBeginColumn = x;
// condition.findBeginRow = y;
console.log("search condition :" );
console.log(condition);
var result = this.doSearch(spread,condition)
if(result.foundColumnIndex<0 || result.foundRowIndex<0){
return allSparkLines;
}
if(result.foundColumnIndex>=colEnd || result.foundRowIndex>=rowEnd){
console.log(result.foundColumnIndex>=colEnd || result.foundRowIndex>=rowEnd)
continue;
}
allSparkLines.push(result);
x=result.foundColumnIndex+1;
y=result.foundRowIndex;
console.log("this time , search result :");
console.log(result);
}
}
return allSparkLines;
}
var onButton = function onButton(){
var allSparkLine = sparkLineHelper.searchFromSelections(spread);
console.log("allSparkLine");
console.log(allSparkLine);
}在searchFromSelections这个function中,两层for循环在execl选中区域(activeSheet.getSelections() 的范围内)进行查找,但是如下图,但是A4不再选中区域内,也被查找到
https://demo.grapecity.com.cn/spreadjs/gc-sjs-samples/index.html 在线可以直接运行 本帖最后由 肉夹馍汉堡 于 2023-2-9 10:03 编辑
https://demo.grapecity.com.cn/spreadjs/gc-sjs-samples/index.html
这个下选择的是14.2.2,在我们项目中使用的是16.0.1版本
您截图中“点击”按钮对应的代码是什么?如何操作可以复现您描述的此问题吗?
请在上述链接demo中补充完整代码,然后下载demo提交在帖子中,并详细描述下复现此问题的操作步骤,这边实际验证下。 html的代码如下:
<button onclick='onButton()'>点击</button>
<div id='ss'></div>
本帖最后由 Lynn.Dou 于 2024-11-18 15:25 编辑
问题已复现,已将此问题记录下来进一步调研原因,待有进展会在贴中通知您。
本贴先做保留处理。
-----------------------------------------------
更新进展,请修改代码为:
condition.searchFlags = GC.Spread.Sheets.Search.SearchFlags.blockRange;
页:
[1]