WPS的JS宏实现Excel表格合并后自动拆分并填充

本方法实现了对excel表格的自动拆分,并对拆分后的单元格进行自动填充。

示例代码如下:

Windows.Item(TextEdit1.Text).Activate();
    let cel = Range("A1");
    let coNum = SpinButton2.Value;//输入需要处理的列数
    rowNu = Application.ActiveSheet.UsedRange.Rows.Count;//区域中使用的有效行数
    let nummb = 0;
    for(j=1;j<coNum;j++)
    {//处理前coNum列的表格
        for(i=3;i<rowNu;i++)
        {    
            cel = Range(Cells.Item(i,j), Cells.Item(i,j));
            if(cel.MergeCells)
            {//合并区域
                celRC = cel.MergeArea.Rows.Count;//每个合并区域包含的行数
                cel.UnMerge();
                for(n=1;n<celRC;n++)
                {
                    nummb = i+n;
                    Cells.Item(nummb,j).Formula = Cells.Item(i,j).Text;
                }
                i = i+celRC-1;
            }
        }
    }     

另一种情况,是表格没有合并,但是需要把数据进行相同的填充。


示例代买如下

 //向下自动填充
    Windows.Item(TextEdit1.Text).Activate();
    let cel = Range("A1");
    let j = SpinButton1.Value;
    rowNu = Application.ActiveSheet.UsedRange.Rows.Count;//区域中使用的有效行数
    for(i=3;i<rowNu;i++)
    {
        if(Cells.Item(i,j).Text =="")
        {
            Cells.Item(i,j).Formula = Cells.Item(i-1,j).Text;
            Cells.Item(i,j).Font.Color = 255;
        }
    }

猜你喜欢

转载自blog.csdn.net/qq_27866305/article/details/124093837