[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

import text file into excel

I want to convert the text file .txt into an Excel file using VC++. I don't want to do by manual method (like
saving the file as .csv and using text import wizard)
The code to convert text file has to be provided.
0
anees31
Asked:
anees31
2 Solutions
 
Nass89Commented:
Search the MSDN for word "Q186122", or visit
http://support.microsoft.com/default.aspx?scid=KB;en-us;q186122
you will find very interesting things.
Good luck
0
 
EssCommented:
Use automation to do it.  First go to the class wizard and then select add class, then select from type library.  Choose the excel type library from the office directory.  For Office 2000 it is excel9.olb.  Add all the classes unless you know that you will not need some of them.  After creating the classes create an instance of the application class.  I don't know the exact name of it but will be similar to _Application;

Create the class instance as follows:
_Application app;
app.CreateDispatch("Excel.Application");
//Create a workbook collection
Workbooks wbooks(app.GetWorkbooks());
//Create a individual workbook that will contain the file
_Workbook wbook;
//Create the workbook by import text file
wbook = wbooks.OpenText(See MS Excel help for parameters);
//Save the workbook
wbook.SaveAs(See MS EXcel help for parameters);
app.DetachDispatch();

I don't know the exact class names but they will be similar to above.  Also if you have to use constants in the functions you cannot use the Excel defined constants.  Open OleView for the Excel automation object and see what the constant's numerical values are.  These are the values you use in the functions created by class wizard.

Good Luck!!
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now