LabWindows/CVI

取消
显示结果 
搜索替代 
您的意思是: 

Word opening

已解决!
转到解答

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

0 项奖励
1 条消息(共 6 条)
4,848 次查看

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 项奖励
2 条消息(共 6 条)
4,770 次查看
Hi Roberto,

and where should I place this CA_GetAutomationErrorString in the code?
I place documents (word templates) in ProgramData.
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.


Thank you for your help
0 项奖励
3 条消息(共 6 条)
4,745 次查看
解答
已被主题作者 MajklS 接受

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);
0 项奖励
4 条消息(共 6 条)
4,734 次查看

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;
}

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 项奖励
5 条消息(共 6 条)
4,728 次查看

Thanks for the advice Roberto.

I wish you a nice day.

 

0 项奖励
6 条消息(共 6 条)
4,706 次查看