Free Support Forum - aspose.com

Transferring a data map to a range of cells

Hi,
Again I am porting over some MS Excel code to Aspose and I am not sure how to accomplish translating the following code. The code builds up a results map and then uses MS Excel's range to copy the data in the map into the required cells:

Public Function PopulateSpreadsheet(ByVal xlSheet As Excel.Worksheet, ByVal rowStart As Integer, ByVal colStart As Integer) As Excel.Worksheet

Dim resMap(,) As Object

Dim row As Integer

Dim col As Integer

Dim rowResultsMax As Integer = UBound(results, 2)

Dim colResultsMax As Integer = UBound(results, 1)

ReDim Preserve resMap(rowResultsMax, colResultsMax)

For row = rowStart To rowResultsMax

For col = colStart To colResultsMax

resMap(row - rowStart, col - colStart) = results(col, row)

Next

Next

xlSheet.Range(.Cells(rowStart, colStart), .Cells(rowResultsMax, colResultsMax)).Value = resMap)

PopulateSpreadsheet = xlSheet

End Function




So far I have translated this as follows:

Public Function PopulateSpreadsheet(ByVal xlSheet As Worksheet, ByVal rowStart As Integer, ByVal colStart As Integer) As Worksheet

Dim resMap(,) As Object

Dim row As Integer

Dim col As Integer

Dim rowResultsMax As Integer = UBound(results, 2)

Dim colResultsMax As Integer = UBound(results, 1)

ReDim Preserve resMap(rowResultsMax, colResultsMax)

For row = rowStart To rowResultsMax

For col = colStart To colResultsMax

resMap(row - rowStart, col - colStart) = results(col, row)

Next

Next

Dim mapRange As Range = xlSheet.Cells.CreateRange(rowStart, colStart, rowResultsMax - rowStart + 1, colResultsMax - colStart + 1)

.........

PopulateSpreadsheet = xlSheet

End Function


I have defined mapRange to cover what I think is the same range as the MS Excel example but I see you cannot just say .PutValue so I am stuck at this point, is there any way I can copy over a data map like this?

Two ways to import your two dimension array.

1. Use Range.Item property to get each Cell and use Cell.PutValue method
2. Use Cells.ImportTwoDimensionArray method to import it.