CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2002
    Posts
    16

    Firing up a Microsoft word document

    I'm working on a project that requires to display data retrieve from DB in a word document.

    Have anyone tried this before? Need help urgently.


  2. #2
    Join Date
    Aug 2000
    Location
    Pgh, PA, USA
    Posts
    134

    Re: Firing up a Microsoft word document

    to fire up a word document, I think this would work...

    STARTUPINFO StartupInfo;
    PROCESS_INFORMATION ProcessInfo;
    memset(&StartupInfo, 0, sizeof(StartupInfo));
    memset(&ProcessInfo, 0, sizeof(ProcessInfo));
    if(CreateProcess(
    NULL,
    "\"C:\\Program Files\\Microsoft Office\\Office\\winword.exe\" c:\\somedir\\doc1.doc",
    NULL,
    NULL,
    FALSE,
    CREATE_DEFAULT_ERROR_MODE,
    NULL,
    NULL,
    &StartupInfo,
    &ProcessInfo) == FALSE)
    {
    // Error
    // Wait until application has finished
    WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
    AfxMessageBox("Could not open file!");
    // Application has finished...
    }



    notice how c:... and winword.exe has quotes around it.


  3. #3
    Join Date
    May 2002
    Posts
    16

    Re: Firing up a Microsoft word document

    Thanks, Jeff. The code helps.

    Wonder if u also know how to generate a report in Microsoft word using VC++? ie. I got some data I retrieve from DB and I wish to view it and print it in MS words.





  4. #4
    Join Date
    Aug 2000
    Location
    Pgh, PA, USA
    Posts
    134

    Re: Firing up a Microsoft word document

    I don't know how to create a .doc file but for a text file, you can do something like this...

    CString csName = "c:\\somedir\\doc1.txt";
    CStdioFile fTextFile;
    if(!fTextFile.Open(csName, CFile::modeWrite | CFile::modeCreate))
    {
    AfxMessageBox("Unable to create file!");
    return;
    }

    // go thru loop accessing info to write and placing in CString csBuf

    fTextFile.WriteString(csBuf);
    fTextFile.WriteString("\n");

    // end of loop here

    fTextFile.Close();



    Hope this helps


  5. #5
    Join Date
    May 2002
    Posts
    16

    Re: Firing up a Microsoft word document

    I just found out we can use "ShellExecute" function to fire up application.

    For example,

    ShellExecute(NULL, "Open", "C:\\Program Files\\Microsoft Office\\Office\\winword.exe", NULL, NULL, SW_SHOW);


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