Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / May 2004

Tip: Looking for answers? Try searching our database.

C#/Excel interop - performance tips?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Xing - 24 May 2004 20:01 GMT
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.
Aaron Queenan - 24 May 2004 20:14 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.