任何在Google电子表格上使用VBA的方法?
无论如何,将excel VBA转换为Google Appscript,以便我可以在Google电子表格上使用它? 我需要下面的代码来转换 –
Sub Test1() Application.ScreenUpdating = False Dim cell As Range, varFind As Variant With Sheets("Sheet1") For Each cell In Sheets("Sheet4").Columns(3).SpecialCells(2) Set varFind = .Columns(6).Find(What:=cell.Value, LookIn:=xlFormulas, LookAt:=xlWhole) If Not varFind Is Nothing Then .Cells(varFind.Row, 4).Value = cell.Offset(0, 2).Value Set varFind = Nothing Next cell End With Application.ScreenUpdating = True End Sub
有些VBA方法和属性在谷歌应用程序脚本中没有直接的等价关系,所以必须进行仿真。 还要注意,最好将所有数据从电子表格中取出并在数组中进行操作。
这与您在VBA中所做的相同,转换为GAS。 你没有提供任何testing数据,所以我没有太多的testing。
function test() { var s1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1'); var s4 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet4'); // best to read in all the values at once var v4 = s4.getDataRange().getValues(); var f4 = s4.getDataRange().getFormulas(); var v1 = s1.getDataRange().getValues(); // look at the formulas in column 3 /sheet 4 to determine if this is a constant specialCellsConstants(2,f4).forEach( function (rc) { // for each constant found, find that same constant in sheet 1, column 6 var f = findInColumn (v4[rc.row][2], v1, 5); // if it was found, then copy the value 2 columns along from sheet4 to sheet 1 colum 4 if (f) { v1[f.row][3] = v4[rc.row][4]; } }); // write back the updated values s1.getDataRange().setValues(v1); } function findInColumn(value,values,column) { // find first occurrence of value in a given column for (var i=0; i < values.length ; i++ ) { if (values[i][column] === value) { return {row:i}; } } return null; } function specialCellsConstants(column,formulas) { // emulate the specialcells function in excel and return array of the addresses of constants var results = []; for (var i = 0; i < formulas.length ; i++ ) { if (!formulas[i][column]) results.push ({row:i}); } return results; }
VBA可以通过GSpread.NET读/写Google Spreadsheet。 它的开源库通过使用Microsoft Excel API与Google表格协同工作。
使用CreateObject(GSpreadCOM.Application)而不是CreateObject(Excel.Application) 。
- 将文本框值与Google电子表格上单元格中存储的值相乘
- JavaScript中的VBA相当于用于Google表格的Google Apps脚本
- getRange,getDataRange和getActiveRange之间的区别?
- Google脚本从Google表格创buildExcel工作簿
- 使用JavaScript来生成包括公式和用户input的电子表格
- 在Google日历和电子表格之间不生成预期的结果
- 使用Google脚本以ms Excel格式创buildGoogle表格的附件
- 使用VBA或Google Apps脚本识别多次出现string的电子表格单元格
- 如何从一个工作表中获取Google Spreadsheet中的数据行,并预填充另一个工作表