Solved

Automation to Excel in C++ using Direct-To-COM

Posted on 2000-03-06
6
377 Views
Last Modified: 2008-02-20
I need to export some tabular data to Excel.8.
So, I am writing :

#import <D:\Program Files\Microsoft Office\Office\EXCEL8.OLB>
.....
boolean MyClass::menuExportTableToExcel()
{

    using namespace Excel;
   _ApplicationPtr pXL;
    try
      {
            pXL.CreateInstance(L"Excel.Application.8");
            pXL->Visible = VARIANT_TRUE;
   
            WorkbooksPtr pBooks = pXL->Workbooks;
               _WorkbookPtr pBook  = pBooks->Add((long)xlWorksheet);

            _WorksheetPtr pSheet = pXL->ActiveSheet;
            pSheet->Name = "Selling Sheet";

            for (int col_i = firstCol; col_i < listt->count(); col_i++)
            {
             
(*)              pSheet->Cells(1,col_i-firstCol+1)->Value = //something;

                 }
            ..........................
}

Compiler issues 4 errors on line (*).
      - term does not evaluate to a function
      - left of '->Value' must point to class/struct/union

I saw in *.tli, tlh files but unfortunatly it did not help
me.

In 2 words, I need in loop put data in EXCEL through _WorkbookPtr. I need something
like that in VB :

For rwIndex = 1 to 4
    For colIndex = 1 to 10
        With Worksheets("Sheet1").Cells(rwIndex, colIndex)
             .Value = "shalom"
        End With
    Next colIndex
Next rwIndex

 

0
Comment
Question by:arikka
  • 3
  • 2
6 Comments
 

Expert Comment

by:Cyberman
ID: 2589557
Without getting into too much detail, it's nothing to do with COM.

pSheet->Cells(1,col_i-firstCol+1)->Value = //something

It seems to think that you're calling
a function Cells()

Cells(1, col_i-firstCol+1)

you probably want square brackets (I'm assuming that Cells is actually a multidimensional array)

Cells[1, col_1-firstCol+1]

RE: - left of '->Value' must point to class/struct/union

This is pointing to the fact that you aren't getting what you want before ->Value

If the idea is to get something back from a function (e.g. Cells() actually returns a cell) you'll have to do

Foo* pCell = Cells(1,col_1-firstCol+1);

and then pSheet->pCell->Value

or whatever.




0
 
LVL 2

Author Comment

by:arikka
ID: 2590989
Adjusted points to 100
0
 
LVL 2

Author Comment

by:arikka
ID: 2590990
I've tried it before, it did not help...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Author Comment

by:arikka
ID: 2591304
Please do not ask me, I already found the soultion !!!


    Excel::RangePtr pRange;
      CString csRange;
      for (int i = 0; i < nLines; i++) // send each line to Excel
        { // one value at at time (till speed becomes an issue
        for (int j = 0; j < sizeof(cBreaks) / sizeof(cBreaks[0]);j++)
          {
          csRange.Format("%c%d", 'A'+j, i+1); // "A1, A2... B1, B2," etc
          pRange = pSheet->Range[(LPCTSTR)csRange];
          int idxChar = i*nLineLength+cBreaks[j]+1; // idx 1 past prev. NUL
          if (idxChar > nLength) // avoid overruns
            break;
          _variant_t tVar(&pC[idxChar]); // point to NUL-terminated string
          pRange->PutValue(&tVar);
0
 
LVL 5

Expert Comment

by:ianB
ID: 2676280
Community Support has reduced points from 100 to 0
0
 
LVL 5

Accepted Solution

by:
ianB earned 0 total points
ID: 2676281
Closing question and keeping answer.

Ian
Community Support @ Experts Exchange
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now