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 / Languages / Managed C++ / June 2005

Tip: Looking for answers? Try searching our database.

Write Data from managed C++ (VS2003 + PIA) into Excel 2003

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Hans Wien - 16 Jun 2005 18:13 GMT
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
Jens Thiel - 16 Jun 2005 22:07 GMT
Hello Hans,

try calling the indexer directly, e.g. something like
theSheet1->Cells->get_Item(i,3).

Jens.

Signature

http://ManagedXLL.net/  |  http://www.stochastix.de/
Replace MSDN with my first name when replying to my email address!

>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
[quoted text clipped - 58 lines]
> Thank you for all your help in advance.
> Hans from Vienna
Hans Wien - 17 Jun 2005 14:58 GMT
Thanks a lot Jens, you solved the problem.
The answer in C++ is:

thesheet1->Cells->set_Item(__box(i), __box(3),__box(i) );

Thank you for your effort.
Hans Wien

> Hello Hans,
>
[quoted text clipped - 65 lines]
> > Thank you for all your help in advance.
> > Hans from Vienna

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.