0

你们能帮帮我吗

我需要将一些 VBA 代码转换为 Office 脚本,我很苦恼,我需要使用某些参数从列中删除数据

这是代码:

Sub processing()

    On Error GoTo Error_Handler

    ' concatenate Macro
    Dim var As String
    Dim row As Integer
    Dim column As Integer
    Dim concatened As String
    Dim hours() As String
    Dim cursor As Integer
    Dim person As Integer
    Dim sum As Double
    
    ' erasing columns

    For column = Sheets("Parameters").Cells(2, 4) To Sheets("Parameters").Cells(2, 5)
        For row = Sheets("Parameters").Cells(2, 2) To Sheets("Parameters").Cells(2, 3)
            
            Sheets("Projects").Cells(row, column) = ""
            
        Next row
        
        Sheets("Projects").Cells(3, column) = ""
        
    Next column
    

如果有人可以告诉我从哪里开始,我会很高兴。

4

1 回答 1

0

您可以使用(Range).clear方法清除任何范围内的数据。

function main(workbook: ExcelScript.Workbook)
{
  const paramSheet = workbook.getWorksheet("Parameters");
  const param: number[] = [
    +paramSheet.getCell(0, 0).getValue(),
    +paramSheet.getCell(0, 1).getValue(),
    +paramSheet.getCell(1, 0).getValue(),
    +paramSheet.getCell(1, 1).getValue()
  ];
  const targetSheet = workbook.getActiveWorksheet();
  const targetRange = targetSheet.getRangeByIndexes(param[0], param[1], param[2], param[3]);
  targetRange.clear(ExcelScript.ClearApplyTo.contents);
}

我建议您参考Basic Samples

于 2021-05-25T04:23:21.050 回答