CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    Dec 2014
    Posts
    8

    Visual C++ 6.0 for Notepad

    hi,
    I have a Visual C++ 6.0 program which automates excel and works with excel files.
    Now I need to work with a text file.
    I am wondering how I can open a Notepad file as an excel one, using my program.

    If anyone can help please do

    Thanks
    Val

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Visual C++ 6.0 for Notepad

    Quote Originally Posted by valera1968 View Post
    hi,
    I have a Visual C++ 6.0 program which automates excel and works with excel files.
    Now I need to work with a text file.
    I am wondering how I can open a Notepad file as an excel one, using my program.

    If anyone can help please do

    Thanks
    Val
    Notepad just uses text files. CStdioFile would work. I don't know if you can automate it or not.

  3. #3
    Join Date
    Dec 2014
    Posts
    8

    Re: Visual C++ 6.0 for Notepad

    thanks for respond.... what I meant was how can i open text file as excel... if i do right mouse click on text file there is an option "Open With" where i can choose excel and my text file will be open not by Notepad but by Excel. my questing was how to do it using the code.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Visual C++ 6.0 for Notepad

    Have a look at CWinApp::RegisterShellFileTypes and CWinApp::EnableShellOpen methods.
    Victor Nijegorodov

  5. #5
    Join Date
    Dec 2014
    Posts
    8

    Re: Visual C++ 6.0 for Notepad

    hi Victor, thanks for your help
    probably i didn’t make it clear.
    I have the program that works with excel files, but the originally the file is in text format.
    So what i have to do is open text as excel manually and then i place it in specific folder where the program can get it.
    What i want to do is to get a code which would open text as excel without the need for user to do it.
    The user only places the text file into the needed folder and the rest is done by the program.
    I also have the program that works with the text file and if i combine both they should work,
    but i prefer the first way.
    Thanks for reading
    Val

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Visual C++ 6.0 for Notepad

    The easiest way to let text file be opened by excel is change its extension from .txt to .csv.
    Victor Nijegorodov

  7. #7
    Join Date
    Dec 2014
    Posts
    8

    Re: Visual C++ 6.0 for Notepad

    hi Victor thanks for your help,
    i saved .txt as .csv and my program didn't get any data from the file
    in .txt file the tab is used to separate the data .csv does something different.
    i will try to change .txt to .xls
    Thanks

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Visual C++ 6.0 for Notepad

    Quote Originally Posted by valera1968 View Post
    hi Victor thanks for your help,
    i saved .txt as .csv and my program didn't get any data from the file
    in .txt file the tab is used to separate the data .csv does something different.
    i will try to change .txt to .xls
    Thanks
    After saving the .txt to .csv, check to make sure it's valid by manually opening it in excel.

    If it doesn't open manually, then fix the .csv format until it does open.

    Once it opens manually, then you can open it in Excel. To do this, I would start with a search in bing or google "programatically open a .csv file in excel using automation"

  9. #9
    Join Date
    Dec 2014
    Posts
    8

    Re: Visual C++ 6.0 for Notepad

    thanks to all who replied to the post.
    I have sorted the problem. first i used CopyFile() witch allows me to convert from .log to .xls. then i used SaveAs(); witch is an excel function and it allows me to save the file as an excel worksheet. now i get another problems because now i have to process more data than at the start. the program will run slower, but at list it works.
    thanks to all for the help and have a nice Christmas!!!

  10. #10
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Visual C++ 6.0 for Notepad

    Quote Originally Posted by valera1968 View Post
    I have sorted the problem. first i used CopyFile() witch allows me to convert from .log to .xls. then [...]
    If you are talking about CopyFile function, please note that it simply copy a file and does NOT perform any conversion.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  11. #11
    Join Date
    Dec 2014
    Posts
    8

    Re: Visual C++ 6.0 for Notepad

    yes, but if i set .xls extension for the copy, then i am able to open the file in excel and work with this file. then later when i have done all work i use SaveAs() (from _Workbook class) where i can specify the file format according to my excel version. it works..... it could be easier if i can automate notepad and use its Select All and Copy functions, then i create an excel sheet, select a sell and use Paste function. it works when i do it manually so it should be possible to do it inside the program.... i may try it later....

  12. #12
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Visual C++ 6.0 for Notepad

    Quote Originally Posted by valera1968 View Post
    yes, but if i set .xls extension for the copy, then i am able to open the file in excel and work with this file. then later when i have done all work i use SaveAs() (from _Workbook class) where i can specify the file format according to my excel version. it works..... it could be easier if i can automate notepad and use its Select All and Copy functions, then i create an excel sheet, select a sell and use Paste function. it works when i do it manually so it should be possible to do it inside the program.... i may try it later....
    Why not just rename it?

    You could always just read the file and put it into the clipboard yourself. There's no need to automate notepad just to read a text file.

  13. #13
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Visual C++ 6.0 for Notepad

    Quote Originally Posted by valera1968 View Post
    it works..... it could be easier if i can automate notepad and use its Select All and Copy functions, then i create an excel sheet, select a sell and use Paste function.
    Probably not easier and most likely less reliable. In programming, driving an application through UI automation is seldom the answer when there are api alternatives. Because of the problems associated with UI automation, it should generally only be used as a last resort.

  14. #14
    Join Date
    Dec 2014
    Posts
    8

    Re: Visual C++ 6.0 for Notepad

    I can't just rename the text file, i have to use Open As option to open the file with the excel application. But this is not the main reason.
    I have user interface done with MFC and the user has to have the easy way, which means pressing one button only. the user sees only the final excel file with analysed data.

  15. #15
    Join Date
    Dec 2014
    Posts
    8

    Re: Visual C++ 6.0 for Notepad

    i am not very experienced with codding and if i have ability to use the excel functions why not to do this. i guess it should be as much reliable as Microsoft excel and all work is hidden form the user.
    what i want is a simple application which will analyze the data originally stored in text file.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured