初始化数据时想选中非表头数据的第一个单元格,使用的是sheet.setActiveCell()。选中改单元格后我想触发Sheets.Events.SelectionChanged事件,然后返回选中单元格所在行的数据。请问该如何触发该事件。spreadSelectionChanged = (spread) => {
const {selectionChanged} = this.props
const activeSheet = spread.getActiveSheet()
spread.bind(GC.Spread.Sheets.Events.SelectionChanged, (e, args) => {
const selection = args.newSelections.pop(),
columnCount = activeSheet.getColumnCount()
if (selection.rowCount === 1) {
const rowIndex = selection.row
let cols = []
// 声明在 for循环上面不可取 会造成cols中的数据都相同
for (let i = 0; i < columnCount; i++) {
const cellHeader = activeSheet.getValue(_.toInteger(0), _.toInteger(i), GC.Spread.Sheets.SheetArea.colHeader)
const value = activeSheet.getCell(_.toInteger(rowIndex), i)
.value()
let col = {header: cellHeader, value: value}
cols.push(col)
}
if (!_.isUndefined(selectionChanged)) {
selectionChanged(cols)
}
}
})
}
|
|