PC Review


Reply
 
 
RobcPettit
Guest
Posts: n/a
 
      3rd Sep 2007
Hi, Im using vs2005 csharp to open a workbook and add data with a
simple array using the code:
Excel.Sheets objSheets;
Excel._Worksheet objSheet;
Excel.Range range;



//WorkBooks.open(string Filename, object UpdateLinks,
object ReadOnly, object Format, object Password, object
WriteResPassword, object ReadOnlyRecommend, object Origin, object
Delimiter, object Editable, object Notify,
//object Converter, object AddToMru, object Local, object
CorruptLoad
Excel.Workbook excelWorkbook =excelApp.Workbooks.Open("C:\
\Documents and Settings\\Robert\\Desktop\\Baccarat two",
0, false, 5, "", "", false, Excel.XlPlatform.xlWindows,
"",
true, false, 0, true, false, false);
excelApp.Visible = true;
try
{

objSheets = excelApp.Worksheets;
objSheet = (Excel._Worksheet)objSheets.get_Item(1);

range = objSheet.get_Range("A50", Missing.Value);
range = range.get_Resize(5, 5);



//Create an array.
double[,] saRet = new double[5, 5];

//Fill the array.
for (long iRow = 0; iRow < 5; iRow++)
{
for (long iCol = 0; iCol < 5; iCol++)
{
//Put a counter in the cell.
saRet[iRow, iCol] = iRow * iCol;
}
}

//Set the range value to the array.
range.set_Value(Missing.Value, saRet);
}



catch (Exception theException)
{
String errorMessage;
errorMessage = "Error: ";
errorMessage = String.Concat(errorMessage,
theException.Message);
errorMessage = String.Concat(errorMessage, " Line: ");
errorMessage = String.Concat(errorMessage,
theException.Source);

MessageBox.Show(errorMessage, "Error");
}


This works with no problems. My query is now Ive got the workbook open
and added the first array, I want to update the data every x-mins. I
want to leave the work book open once initially opened. I cant work
out how to reference the already opened workbook though. I can
ofcourse close and reopen the workbook but this isnt very efficient.
Any ideas.
Regards Robert

 
Reply With Quote
 
 
 
 
RobcPettit
Guest
Posts: n/a
 
      3rd Sep 2007
I think ive craked it. Ive used excelApp =
(Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
to reference the rot table. I also found that I wasnt closing the file
correctly which left instance of excel in the procceses. If I get more
than one this code wont work.
Regards Robert

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
any one who knows some website about the socket with cshap.net ? kylin Microsoft Dot NET Framework Forms 2 18th Oct 2005 07:05 AM
If exist a control in CShap that like the VB6 control RepeaterControl muhamad Microsoft C# .NET 1 21st Sep 2004 01:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:00 AM.