|
-
May 7th, 2002, 08:50 AM
#1
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.
-
May 7th, 2002, 09:58 AM
#2
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.
-
May 8th, 2002, 05:57 PM
#3
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.
-
May 9th, 2002, 03:17 PM
#4
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
-
May 10th, 2002, 02:29 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|