G
Guest
I'm trying to use excel automation (from visual c# .NET) to fill data in a
range by using arrays. I am using Microsoft's Knowledge Base Article 302096
as a reference and using the example listed there, but I'm having trouble
with the following code:
**************** Code Starts Here ***********
Excel.Application m_objExcel;
Excel.Workbooks m_objBooks;
Excel._Workbook m_objBook;
Excel.Sheets m_objSheets;
Excel._Worksheet m_objSheet;
Excel.Range m_objRange;
m_objExcel = new Excel.Application();
m_objExcel.Visible = true;
m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;
m_objBook = (Excel._Workbook)m_objBooks.Add(Missing.Value);
m_objSheets = (Excel.Sheets)m_objBook.Worksheets;
m_objSheet = (Excel._Worksheet)(m_objSheets.get_Item(1));
m_objRange = m_objSheet.get_Range("A1", Missing.Value);
m_objRange = m_objRange.get_Resize(5, 5);
double[,] doubleGrid = new double[5,5];
for (int row = 0; row < 5; row++)
{
for (int column = 0; column < 5; column++)
{
doubleGrid[row,column] = row * column;
}
}
m_objRange.set_Value(Missing.Value, doubleGrid);
*************** Code Ends Here *************
Microsoft Excel opens up okay, but then the server throws an exception (in
excel). I'm not able to figure out what the problem is, but I have a feeling
that it's something with Range.set_Value method.
Any ideas??
Thanks.
Mansi
range by using arrays. I am using Microsoft's Knowledge Base Article 302096
as a reference and using the example listed there, but I'm having trouble
with the following code:
**************** Code Starts Here ***********
Excel.Application m_objExcel;
Excel.Workbooks m_objBooks;
Excel._Workbook m_objBook;
Excel.Sheets m_objSheets;
Excel._Worksheet m_objSheet;
Excel.Range m_objRange;
m_objExcel = new Excel.Application();
m_objExcel.Visible = true;
m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;
m_objBook = (Excel._Workbook)m_objBooks.Add(Missing.Value);
m_objSheets = (Excel.Sheets)m_objBook.Worksheets;
m_objSheet = (Excel._Worksheet)(m_objSheets.get_Item(1));
m_objRange = m_objSheet.get_Range("A1", Missing.Value);
m_objRange = m_objRange.get_Resize(5, 5);
double[,] doubleGrid = new double[5,5];
for (int row = 0; row < 5; row++)
{
for (int column = 0; column < 5; column++)
{
doubleGrid[row,column] = row * column;
}
}
m_objRange.set_Value(Missing.Value, doubleGrid);
*************** Code Ends Here *************
Microsoft Excel opens up okay, but then the server throws an exception (in
excel). I'm not able to figure out what the problem is, but I have a feeling
that it's something with Range.set_Value method.
Any ideas??
Thanks.
Mansi