首页 > 解决方案 > Office JS: Is there a way to find the last row with data in on an excel sheet so that i can then copy that information onto another sheet?

问题描述

I have previously used VBA to find the last row that contains data on an excel sheet and the used this to copy specific cells on that sheet across to another excel sheet, however we have now begun using excel online so i was wondering if there was any way to replicate this in office JS?

An example of the VBA code that i was using before for reference is below, is there any way for this to be easily converted into office JS?

Sub FormCreate()

ThisWorkbook.Sheets("Data").Activate
ThisWorkbook.Sheets("Data").Cells(Rows.Count, 1).End(xlUp).Select
ThisWorkbook.Sheets("Form").Range("A1") = Sheets("Data").Range("A" & (ActiveCell.Row))
ThisWorkbook.Sheets("Form").Range("B4") = Sheets("Data").Range("B" & (ActiveCell.Row))
ThisWorkbook.Sheets("Form").Range("F1") = Sheets("Data").Range("C" & (ActiveCell.Row))
ThisWorkbook.Sheets("Form").Range("E3") = Sheets("Data").Range("D" & (ActiveCell.Row))
ThisWorkbook.Sheets("Form").Range("F4") = Sheets("Data").Range("E" & (ActiveCell.Row))
ThisWorkbook.Sheets("Form").Range("D2") = Sheets("Data").Range("F" & (ActiveCell.Row))

End Sub

Thanks JM

标签: exceloffice-js

解决方案


试试这个:使用Worksheet.getUsedRange方法获取包含数据的整个范围。然后在返回的 Range 对象上,调用Range.getLastRow方法。然后读取返回的 Range 对象的Range.values属性。


推荐阅读