Nicole Pinto
Nicole Pinto

Reputation: 364

How can I copy an array to each cell of a column starting from a certain cell, instead of to each cell of a row?

How can I copy an array so that it copies into each cell going down Column F, instead of going across a certain row, like I have in my code now. In this case it's row "7". How can I do this and start at a certain cell, let's say F3. I am currently using ExcelJS, but would be open to try other things.

Index.Js

var Excel = require('exceljs');

       var captureNames = [1,2,3,A,B,C];

   workbook.xlsx.readFile("X:\\TESTING_DATA\\eclipse-database\\myExcelFile.xlsx")
          .then(function() {

            var sheet = workbook.addWorksheet('My Sheets');
            var worksheet = workbook.getWorksheet("My Sheets");

            var row = worksheet.getRow(7);
            row.values = captureNames;

            return workbook.xlsx.writeFile("X:\\TESTING_DATA\\eclipse-database\\myExcelFile.xlsx");


        })

What I get now

enter image description here What I want

enter image description here

Upvotes: 1

Views: 2601

Answers (2)

Nicole Pinto
Nicole Pinto

Reputation: 364

Just had to add a formula like this, thanks @dotsu !

 captureNames.forEach(function(name, i) {
                        worksheet.cell('F' + (3 + i)).value(name);
                    })

Upvotes: 1

dostu
dostu

Reputation: 1518

Didn't test because of lack of example file, but you should do something similar:

captureNames.forEach(function(name, i) {
  worksheet.getCell('F' + (3 + i)).value = name
})

Upvotes: 2

Related Questions