Tim Scarborough
Tim Scarborough

Reputation: 1290

Assign Excel Range to a Javascript Array

I'm working on some code to export a DataTable to Excel, and I'm trying to make it as fast as possible. Right now, I'm looping through each row and each column for each row (nested for loops). When I've got a large DataTable, this process can take some time. Can I assign a range of cells to an array in Javascript instead of looping through the columns?

Here's a sample of what I'm doing.

for (var rowIndex = 0; rowIndex < json.worksheets.raw.rows.count; rowIndex++) {
    row = rowIndex + 2;
    for (var columnIndex = 0; columnIndex < json.worksheets.raw.rows.values[rowIndex].length; columnIndex++) {
        column = columnIndex + 1
        XLWorksheet.Cells(row, column) = json.worksheets.raw.rows.values[rowIndex][columnIndex];
    }
}

I get the JSON data using an AJAX call to a web service in my ASP.NET project.

Upvotes: 0

Views: 3459

Answers (1)

GSerg
GSerg

Reputation: 78155

You can do XLWorksheet.Range("A1:C100").value = arr, if arr is an array of VARIANT.

Upvotes: 1

Related Questions