我对 JS 很陌生。我在 Google Script 中写了一个简单的函数。它在 Google 表格中运行良好。但是,将工作表下载为 Microsoft Excel 时会出错。我的功能如下。
function test(input){
var str = "";
for(i=0; i<input.length; i++){
for(j=0; j<input[i].length; j++){
var char0 = input[i][j].charAt(0).toUpperCase();
var sub = input[i][j].substr(1,input[i][j].length);
str = str.concat(char0,sub,",");
}
}
return str;
}
最佳答案
较新版本的 Microsoft Excel 支持 javascript。见下面的链接
Create custom functions in Excel
通过此链接,您需要具有以下版本才能使用此功能。
Note that Excel custom functions are available on the following platforms.
- Office on Windows (version 1904 or later, connected to Office 365 subscription)
- Office on Mac (version 16.24 or later, connected to Office 365 subscription)
- Office on the web
- Excel custom functions are currently not supported on iPad or in one-time purchase versions of Office 2019 or earlier.
或者,您可以使用 VBA 构建一个用户定义的函数,如果您想继续使用具有上述以外版本的 Excel,该函数将获得类似的结果。
等效的 VBA UDF 如下所示,可以以非常相似的方式在单元格中使用,即 =UCaseString(K2)
,其中数据位于单元格 K2
Function UCaseString(strInput As String) As String
Dim i As Long
UCaseString = ""
For i = 1 To Len(strInput)
UCaseString = UCaseString & Mid(UCase(strInput), i, 1) & ","
Next i
End Function
关于javascript - 下载为 Microsoft Excel 时,Google Script 中的自定义函数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59207165/