Solved

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

Posted on 2000-03-06
6
376 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 learn how to clear a vector as well as how to detect empty vectors in C++.

707 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

18 Experts available now in Live!

Get 1:1 Help Now