views:

447

answers:

1

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.

+1  A: 

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

GSerg
I tried setting the value to an array, but Excel put a comma separated list of the values into each cell. Is there a VARIANT array in Javascript?
Tim
Created a dictionary and passed that in as the value. Works! Thanks!
Tim