Hi,
does anyone know why it doesn't work for me to open a word right away?
First I initialize where the word is (the path is c: \\ ProgramData \\) in MessagePopup is correct.
Fmt(wordPathName,"%s%s",g_UserProfile,"\\P07_GPT_VizZavady_L3.doc");
initWordZavad(wordPathName); //inicializuje formulář wordu
MessagePopup ("Info", wordPathName);
Now I'm calculating some data to write.
Subsequent word path check.
And then the word should open for me and it won't open.
MessagePopup is correct.
if(celkemZaznamu>0) //Zobrazení vyplněného protokolu
{
//GetProjectDir (wordPathName);
//strcat (wordPathName, "\\P07_GPT_VizZavady_L3.doc");
MessagePopup ("Ahoj", wordPathName);
WordRpt_DocumentOpen (g_appHandle, wordPathName, &g_docHandle);//Zobrazí protokol
MessagePopup ("Ahoj", wordPathName);
SmazPoslStranku(pocetListu);
WordRpt_GoToDocumentTop (g_docHandle);
}
Couldn't there be a problem here? :
void initWordZavad(char *prtokolName)
{
char wordPathName[MAX_PATHNAME_LEN];
if (g_docHandle)
{
CA_DiscardObjHandle (g_docHandle);
g_docHandle = 0;
}
if (g_appHandle)
{
WordRpt_ApplicationQuit (g_appHandle, 0);
CA_DiscardObjHandle (g_appHandle);
g_appHandle = 0;
}
// Open new Word application and open document
WordRpt_ApplicationNew (FALSE, &g_appHandle);
GetProjectDir (wordPathName);
strcat (wordPathName, prtokolName);
WordRpt_DocumentOpen (g_appHandle, wordPathName, &g_docHandle);
WordRpt_AddPageNumbers (g_docHandle, WRConst_Footer,WRConst_AlignPageNumberRight, WRConst_TRUE); //Umístění čísla na stránce
}
I don't know how to do it, the file is located there, but it just won't open it.
Thank you for the advice.
Nice day
已解决! 转到解答。
Hi, first of all, you must add a reasonable error checking in order to understand why things are not working: trapping the return value from the functions is the usual way to do it and Word Report instrument functions follow this rule, with negative return values indicating an error. Passing this value to CA_GetAutomationErrorString gives you a meaningful description of the error.
Second hint, I would test the function putting the file in another folder, just to be sure that you aren't getting protection errors accessing files in a system folder.
g_UserProfile=getenv("ALLUSERSPROFILE");
I had to put the files in a different folder than Program Files, because I would prevent windows from opening to open these files.
I've already figured it out, I've opened the document twice, so the document path was nonsense.
Thank you.
Nice day
GetProjectDir (wordPathName);
strcat (wordPathName, prtokolName);
Ok, I'm happy to know that you solved your problem.
Regarding the error checking (something that I urge you to incorporate in your program) you could do something along this line:
error = WordRpt_DocumentOpen (g_appHandle, wordPathName, &g_docHandle);
if (error < 0) {
CA_GetAutomationErrorString (error, message, 1024);
MessagePopup ("Error!", message);
goto EndOfFunction;
}