excel - 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
解决方案
试试这个:使用Worksheet.getUsedRange方法获取包含数据的整个范围。然后在返回的 Range 对象上,调用Range.getLastRow方法。然后读取返回的 Range 对象的Range.values属性。
推荐阅读
- arrays - Scala - 数组中的并行处理公式
- python - 如何在没有多级索引的情况下创建 groupby 数据框
- python - 有没有办法使用 Selenium for Python 搜索 HTML 元素的“newreq”部分的“data-ftjson”标签?
- python - python中的Selenium多个选项卡“错误:没有这样的窗口:目标窗口已关闭”
- linux - 正则表达式在linux中替换多个文件
- javascript - 加载后图像向下跳一个像素
- jupyter-notebook - 使用 Jupyter Notebook 创建 Watson Studio 项目
- keytool - Quarkus MP-JWT:如何生成密钥对?
- python - scipy.stats.distributions.fit 是如何工作的?
- mongodb - MongoDB 聚合或 MapReduce 将值传递给每个文档