Solved

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

Posted on 2000-03-06
6
380 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
FMX enumerated colours 2 157
thread-safe code in c++ 2 128
Dialogbox API leak? 18 120
need help ...get stuck at middle of coding ...need to submit by Sunday C++ 1 55
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

710 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