0

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.

3
  • Could you add tags for people to understand, where json.worksheets come from? Commented Jun 25, 2009 at 17:55
  • is there a framework that has the object model with json.worksheets object? Commented Jun 25, 2009 at 17:56
  • json.worksheets is a property of my json data after doing the eval() call. No framework. Commented Jun 25, 2009 at 19:26

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

5 Comments

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?
Created a dictionary and passed that in as the value. Works! Thanks!
And exactly what did you do? Assigning a JavaScript Object does not work, nor does a new ActiveXObject("Scripting.Dictionary"). So what's this dictionary of yours?
Please, @TimScarborough How did you do that? (Created a dictionary and passed that in as the value)
@manuell sorry, but I asked this question a decade ago. I don't even remember what project this was on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.