本帖最后由 Richard.Ma 于 2022-12-29 14:32 编辑
是的,这块目前和excel的逻辑稍有不同
在两个单元格合并且左上角单元格为空时:
spread会直接合并为左侧的单元格
excel会先把右侧的单元格值给左侧单元格,然后再合并。(你可以测试再次取消合并,会发现左侧单元格有值,右侧单元格反而没值了)
在spreadjs在线编辑器中要实现相同功能的话,可以直接重写一下合并单元格按钮的command来实现
具体demo可以参考下面的链接
https://jscodemine.grapecity.com ... Fsrc%2Fapp.js%22%7D
核心代码
- var config = GC.Spread.Sheets.Designer.DefaultConfig;
- rewriteMregeCell(config);
- designer.setConfig(config);
- //重写合并居中单元格按钮,补充在左上角单元格为空时,使用后续的单元格为合并单元格的值
- function rewriteMregeCell(config){
- let newcommand=GC.Spread.Sheets.Designer.getCommand('mergeCenter');
- let oldExecute = newcommand.execute;
-
- newcommand.execute = function (context, propertyName, args) {
- let sheet=new GC.Spread.Sheets.Worksheet();
- sheet=context.Spread.getActiveSheet();
- var selections=sheet.getSelections();
-
- selections.forEach((selection)=>{
- if(sheet.getValue(selection.row,selection.col)==null){
-
- for (let i = selection.row; i <selection.row+selection. rowCount; i++) {
- for (let j = selection.col; j <selection.col+selection.colCount; j++) {
-
- if (sheet.getValue(i, j) !== null) {
- sheet.setValue(selection.row,selection.col,sheet.getValue(i,j));
- break;
- }
- }
- }
- }
- });
- oldExecute.call(this, context, propertyName, args);
- }
- config.commandMap={};
- config.commandMap['mergeCenter'] = newcommand;
- }
复制代码
|