EXCELJS eachRow
时间: 2023-08-01 18:06:44 浏览: 59
The "eachRow" function in ExcelJS allows you to iterate over each row in a worksheet. Here is an example code snippet:
```javascript
const workbook = new ExcelJS.Workbook();
const worksheet = workbook.addWorksheet('My Sheet');
// Add some rows to the worksheet
worksheet.addRow([1, 'John', 'Doe']);
worksheet.addRow([2, 'Jane', 'Doe']);
worksheet.addRow([3, 'Bob', 'Smith']);
// Iterate over each row
worksheet.eachRow({ includeEmpty: false }, function(row, rowNumber) {
console.log(`Row ${rowNumber} = ${row.getCell(2).value}`);
});
```
In this example, we create a new workbook and worksheet, and add some rows to the worksheet. We then use the "eachRow" function to iterate over each row in the worksheet, and log the value of the second cell in each row to the console. Note that we pass in an options object with the "includeEmpty" property set to "false", which tells ExcelJS to only iterate over non-empty rows.
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)