R
RobcPettit
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
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