I am writing a C# application which reads data from an Excel workbook and writes the process result back to another Excel workbook. Currently I am using a one-cell range object to locate one cell by row & col id for each read and write. (i.e. everytime, I use the range object to refer to one cell and operates on its Value2 property)
Effectively I guess for each read and/or write, it creates a new Range object(???) and issue a COM call
Therefore I wonder is there any easier way to block read / write. For example, is there a way to issue a command say "Read all the cells in a range (e.g. 1000 x 100) and return their Value2 in a collection-type object"? (Unfortunately I don't have the control of the sorce Excel workbook, so cannot create named range in that workbook.
If you get the Range object for a group of cells, the Value2 member returns
an array containing the Value2 members for each cell.
Regards,
Aaron Queenan.
> I am writing a C# application which reads data from an Excel workbook and writes the process result back to another Excel workbook. Currently I am
using a one-cell range object to locate one cell by row & col id for each
read and write. (i.e. everytime, I use the range object to refer to one cell
and operates on its Value2 property).
> Effectively I guess for each read and/or write, it creates a new Range object(???) and issue a COM call.
>
> Therefore I wonder is there any easier way to block read / write. For example, is there a way to issue a command say "Read all the cells in a
range (e.g. 1000 x 100) and return their Value2 in a collection-type
object"? (Unfortunately I don't have the control of the sorce Excel
workbook, so cannot create named range in that workbook.)
Xing - 27 May 2004 10:26 GMT
Thanks. It looks OK when reading from Value2, is there a way to "batch write" as well? It seems that if I assign an array object back to the Value2 object, only the first cell is updated
The following code can read the data successfully, but only the first cell is updated when write back
-------------------------------------------------------------------------------
Excel.Range oRng = (Excel.Range)oWS.get_Range("A1", "B4")
object[,] data = (object[,])oRng.Value2
for(int i=1; i<=data.GetUpperBound(0); i++
for(int j = 1; j <= data.GetUpperBound(1); j++
Console.WriteLine("(" + i + "," + j + ") = " + data[i,j])
data[i,j] = "NEW" + data[i,j]
oRng.Value2 = data;
Xing - 27 May 2004 11:41 GMT