Solved

How To Rename A Spreadsheet And Save The Worbook To A Specific File Location

Posted on 2011-03-23
2
250 Views
Last Modified: 2012-05-11
I have created and opened a new Excel spreadsheet using COM in Visual Studio 2010 C++.  How can I rename a sheet in the workbook and how can I save the workbook to a specific location?  I made this worth 500 because I put 2 questions in here but I'm pretty sure they are easy answers.  I just don't know the correct method to use or where to look to find a list of methods available through COM for Excel.

XL.CreateInstance(L"Excel.Application");
XL->Visible = true;
XL->Workbooks->Add();
Excel::_WorkbookPtr p_workbook=XL->ActiveWorkbook;
Excel::_WorksheetPtr pSheet = p_workbook->ActiveSheet;

Open in new window

0
Comment
Question by:rgrguric
[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
  • 2
2 Comments
 

Accepted Solution

by:
rgrguric earned 0 total points
ID: 35235083
Looks like I'm gonna answer my own question!  

To rename a sheet in Excel through C++ COM:

Excel::_WorksheetPtr hosenSheet(XL->Worksheets->Item[7]); //Stores ptr to Sheet 7 as chosenSheet
chosenSheet->Name = "Compat Rules"; //Renames Sheet7 to Compat Rules

Open in new window


And finally to save the workbook to a specific location:

char outputPath[200];
char* wndwsUserID = getenv("USERNAME"); //Gets current user logon name for windows
strcpy(outputPath,"C:\\Documents and Settings\\");
strcat(outputPath, wndwsUserID); 
strcat(outputPath,"\\Desktop\\test.xls");

Open in new window

0
 

Author Closing Comment

by:rgrguric
ID: 35235093
No one else posted any comments so I work on this all weekend and came up with a solution!
0

Featured Post

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!

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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++.

635 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