G
Guest
I have to write a lot of data to excel for analysts who use it further from
there but would like to use managed C++ and not C# since a lot of code is
involved which already exists now in managed C++.
In C# I could handle it easily as you can see in this sample:
using Excel = Microsoft.Office.Interop.Excel;
....
private Excel.Application thisApplication;
private Excel.Workbook myWorkbook1;
private Excel.Worksheet theSheet1;
....
void simple_function()
{
thisApplication = new Excel.ApplicationClass();
thisApplication.Visible = true;
myWorkbook1 = thisApplication.Workbooks.Add(Type.Missing);
theSheet1 = (Excel.Worksheet) myWorkbook1.ActiveSheet;
thisApplication.ScreenUpdating = false;
for(int i=1;i<=20;i++)
theSheet1.Cells[i,3] = i;
thisApplication.ScreenUpdating = true;
}
In managed C++ (VS2003) I can do almost the same but get a certain error
message regarding pointer arithmetic during compilation:
using namespace Microsoft::Office::Interop::Excel;
....
private: Microsoft::Office::Interop::Excel::Application * myExcelApplication1;
private: Microsoft::Office::Interop::Excel::Workbook * myWorkbook1;
private: Microsoft::Office::Interop::Excel::Worksheet * theSheet1;
....
void simple_function()
{
myExcelApplication1 = new
Microsoft::Office::Interop::Excel::ApplicationClass();
myExcelApplication1->Visible = true;
myWorkbook1 = myExcelApplication1->Workbooks->Add(Type::Missing);
theSheet1 = dynamic_cast<Microsoft::Office::Interop::Excel::Worksheet *>
(myWorkbook1->ActiveSheet);
myExcelApplication1->ScreenUpdating = false;
for(int i=1;i<=20;i++)
theSheet1->Cells[i,3] = i;
myExcelApplication1->ScreenUpdating = true;
}
During compilation regarding the statement
theSheet1->Cells[i,3] = i;
I get the errormessage
error C2845: '[' : cannot perform pointer arithmetic on __gc pointer
'Microsoft::Office::Interop::Excel::Range __gc *'
Is someone able to help me walk around that problem or do I have to take
other measures to proceed?
Thank you for all your help in advance.
Hans from Vienna
there but would like to use managed C++ and not C# since a lot of code is
involved which already exists now in managed C++.
In C# I could handle it easily as you can see in this sample:
using Excel = Microsoft.Office.Interop.Excel;
....
private Excel.Application thisApplication;
private Excel.Workbook myWorkbook1;
private Excel.Worksheet theSheet1;
....
void simple_function()
{
thisApplication = new Excel.ApplicationClass();
thisApplication.Visible = true;
myWorkbook1 = thisApplication.Workbooks.Add(Type.Missing);
theSheet1 = (Excel.Worksheet) myWorkbook1.ActiveSheet;
thisApplication.ScreenUpdating = false;
for(int i=1;i<=20;i++)
theSheet1.Cells[i,3] = i;
thisApplication.ScreenUpdating = true;
}
In managed C++ (VS2003) I can do almost the same but get a certain error
message regarding pointer arithmetic during compilation:
using namespace Microsoft::Office::Interop::Excel;
....
private: Microsoft::Office::Interop::Excel::Application * myExcelApplication1;
private: Microsoft::Office::Interop::Excel::Workbook * myWorkbook1;
private: Microsoft::Office::Interop::Excel::Worksheet * theSheet1;
....
void simple_function()
{
myExcelApplication1 = new
Microsoft::Office::Interop::Excel::ApplicationClass();
myExcelApplication1->Visible = true;
myWorkbook1 = myExcelApplication1->Workbooks->Add(Type::Missing);
theSheet1 = dynamic_cast<Microsoft::Office::Interop::Excel::Worksheet *>
(myWorkbook1->ActiveSheet);
myExcelApplication1->ScreenUpdating = false;
for(int i=1;i<=20;i++)
theSheet1->Cells[i,3] = i;
myExcelApplication1->ScreenUpdating = true;
}
During compilation regarding the statement
theSheet1->Cells[i,3] = i;
I get the errormessage
error C2845: '[' : cannot perform pointer arithmetic on __gc pointer
'Microsoft::Office::Interop::Excel::Range __gc *'
Is someone able to help me walk around that problem or do I have to take
other measures to proceed?
Thank you for all your help in advance.
Hans from Vienna