943,865 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 384
  • C++ RSS
May 20th, 2009
0

VC++ and MSExcel 2003 sheets handling

Expand Post »
Hy, I have to develop an application usign Visual C++ 2008 that should handle (open, change cells and save) some Excel 2003 sheets. I am using .NET Framework 3.5 and the COM reference Interop.Excel.1.5.
Does anyboby knows how to code this?
Thanks.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pferian is offline Offline
3 posts
since May 2009
May 20th, 2009
0

Re: VC++ and MSExcel 2003 sheets handling

Read the manual.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
May 20th, 2009
0

Re: VC++ and MSExcel 2003 sheets handling

Here is one way to do it , I think, without the complications of COM. The GUI interface is probably not what you want but you can extract the ideas that document presents.
Last edited by Ancient Dragon; May 20th, 2009 at 9:05 am. Reason: add link
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,951 posts
since Aug 2005
May 20th, 2009
0

Re: VC++ and MSExcel 2003 sheets handling

Here is one way to do it without the complications of COM.
Where?

At OP:
You might want to use CSV-files from excel. The CSV files can easily be opened and edited with C++ because they are plain text, so no need for COM
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
May 20th, 2009
0

Re: VC++ and MSExcel 2003 sheets handling

Click to Expand / Collapse  Quote originally posted by niek_e ...
Where?
Oops! link added.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,951 posts
since Aug 2005
May 20th, 2009
0

Re: VC++ and MSExcel 2003 sheets handling

I found the way myself. This is the code that works:

private: System::Void button7_Click(System::Object^ sender, System::EventArgs^ e)
{
String^ XlsFile = String::Format("Z:\\Documenti\\Lavoro\\Fatture\\2009\\Fattura_02_AEM_marzo_09.xls");
String^ XlsSheet = String::Format("Milano, {0}/{1}/{2}",
dateTimePicker1->Value.Day.ToString(),
dateTimePicker1->Value.Month.ToString(),
dateTimePicker1->Value.Year.ToString());

Excel::Application^ oXLApp;
Excel::Workbook^ oXLWBook;
//Excel::Sheets^ oXLSheet;
//Excel::Worksheet^ oXLWSheet;

Excel::Range^ rng;

//starts Excel application
oXLApp = (gcnew Excel::Application());
oXLApp->Visible = true;
//opens the workbook of the file "XlsFile"
oXLWBook = oXLApp->Workbooks->Open(XlsFile, 0, false, 5, "", "",
true,Excel::XlPlatform::xlWindows, "\t", true, false, 0, false, true, true);
//updates the range of sheet1, cell D4
rng = oXLApp->Range::get("D4","D4");
rng->Value2 = XlsSheet;

}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pferian is offline Offline
3 posts
since May 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: mfc graphic editor visual studio 6.0
Next Thread in C++ Forum Timeline: Confusing C++ syntax





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC