Solved

How to use TExcelApplication TExcelWorkBook TExcelWorksheet in builder 6

Posted on 2004-09-23
5
12,269 Views
Last Modified: 2013-11-17
I am trying to read an Excel file, I was provided the following code but I can not make it compile. Can you provide name of book(s) that explain how to use these components. I have placed the compiler error messages that I get at the end.

  WideString fname = "c:\\test.xls";
        WideString sname = "Hello World";
        RangePtr r;
        Excel->Connect();
        Book->ConnectTo(Excel->Workbooks->Open(fname));
        Sheet->ConnectTo(Book->Worksheets->get_Item(1));

        Excel->Set_Visible(0, True);
        Sheet->Set_Name(sname);
        r = Sheet->Cells->SpecialCells(xlCellTypeLastCell);
        long x = r->Column;
        long y = r->Row;
        r->set_Formula("=sum(a1:b3)+1000");
        long v = r->get_Value();
        Sheet->Cells->set__Default(y+1, 1, v);
        r = Sheet->Cells->get_Range_("a1", "b20");
        FontPtr f = r->get_Font();
        r->set_Formula("=rand()");
        r = r = Sheet->Cells->SpecialCells(xlCellTypeLastCell);
        y = r->Row;
        Sheet->Cells->set__Default(y+2, 1, "=average(a1:b20)");
        Sheet->Cells->Calculate();
        f->set_Color(clRed);

Complier Error Messages

[C++ Error] Unit1.cpp(21): E2285 Could not find a match for 'Sheets::get_Item(int)'
  [C++ Error] Unit1.cpp(23): E2316 'Set_Visible' is not a member of 'TExcelApplication'
  [C++ Error] Unit1.cpp(24): E2316 'Set_Name' is not a member of 'TExcelWorksheet'
  [C++ Error] Unit1.cpp(28): E2034 Cannot convert 'char *' to 'tagVARIANT'
  [C++ Error] Unit1.cpp(28): E2342 Type mismatch in parameter 'Param1' (wanted 'tagVARIANT', got 'char *')
  [C++ Error] Unit1.cpp(29): E2034 Cannot convert 'tagVARIANT' to 'long'
  [C++ Error] Unit1.cpp(30): E2034 Cannot convert 'long' to 'tagVARIANT'
  [C++ Error] Unit1.cpp(30): E2342 Type mismatch in parameter 'RowIndex' (wanted 'tagVARIANT', got 'long')
  [C++ Error] Unit1.cpp(30): E2034 Cannot convert 'int' to 'tagVARIANT'
  [C++ Error] Unit1.cpp(30): E2342 Type mismatch in parameter 'ColumnIndex' (wanted 'tagVARIANT', got 'int')
  [C++ Error] Unit1.cpp(30): E2034 Cannot convert 'long' to 'tagVARIANT'
  [C++ Error] Unit1.cpp(30): E2342 Type mismatch in parameter 'Param3' (wanted 'tagVARIANT', got 'long')
  [C++ Error] Unit1.cpp(31): E2034 Cannot convert 'char *' to 'tagVARIANT'
  [C++ Error] Unit1.cpp(31): E2342 Type mismatch in parameter 'Cell1' (wanted 'tagVARIANT', got 'char *')
  [C++ Error] Unit1.cpp(31): E2034 Cannot convert 'char *' to 'tagVARIANT'
  [C++ Error] Unit1.cpp(31): E2342 Type mismatch in parameter 'Cell2' (wanted 'tagVARIANT', got 'char *')
  [C++ Error] Unit1.cpp(33): E2034 Cannot convert 'char *' to 'tagVARIANT'
  [C++ Error] Unit1.cpp(33): E2342 Type mismatch in parameter 'Param1' (wanted 'tagVARIANT', got 'char *')
  [C++ Error] Unit1.cpp(36): E2034 Cannot convert 'long' to 'tagVARIANT'
  [C++ Error] Unit1.cpp(36): E2342 Type mismatch in parameter 'RowIndex' (wanted 'tagVARIANT', got 'long')
  [C++ Error] Unit1.cpp(36): E2034 Cannot convert 'int' to 'tagVARIANT'
  [C++ Error] Unit1.cpp(36): E2342 Type mismatch in parameter 'ColumnIndex' (wanted 'tagVARIANT', got 'int')
  [C++ Error] Unit1.cpp(36): E2034 Cannot convert 'char *' to 'tagVARIANT'
  [C++ Error] Unit1.cpp(36): E2342 Type mismatch in parameter 'Param3' (wanted 'tagVARIANT', got 'char *')
  [C++ Error] Unit1.cpp(38): E2034 Cannot convert 'const TColor' to 'tagVARIANT'
  [C++ Error] Unit1.cpp(38): E2228 Too many error or warning messages


0
Comment
Question by:Masood_b
  • 2
5 Comments
 
LVL 16

Expert Comment

by:George Tokas
Comment Utility
Hello there,

Some books you will find usefull info are:
C++Builder 4 Unleashed.
C++ Builder 5 Developer's guide
C++ Builder 6 Developer's guide

gtokas.
0
 

Author Comment

by:Masood_b
Comment Utility
Thank you for your response, I looked at C++ Builder 6 Developer's guide I did not see any documentation for TExcelApplication TExcelWorkBook TExcelWorksheet.

Can you suggest what I should be looking for.

Thanks you
0
 
LVL 16

Accepted Solution

by:
George Tokas earned 125 total points
Comment Utility
Sorry you are right.
C++Builder5 Developer's guide have examples.
Also C++Builder 4 unleashed.

Check out for examples at borland's community site. Maybe there are some.
http://community.borland.com

gtokas.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

772 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

10 Experts available now in Live!

Get 1:1 Help Now