LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

General Protection Fault using ExcelRpt_WriteData with string data

I get a general protection fault when I try to write multiple strings to a range of cells.

What am I doing wrong?  This is what my statements look like:

 

int SaveDataToExcel(void)
{
char strModuleLabels[6][3];

 //Dummy labels for now...
 strcpy(strModuleLabels[0] , "1A");  //These labels will come from
 strcpy(strModuleLabels[1] , "2A");  //different source when
 strcpy(strModuleLabels[2] , "3A");  //the Excel code is working
 strcpy(strModuleLabels[3] , "1B"); 
 strcpy(strModuleLabels[4] , "2B"); 
 strcpy(strModuleLabels[5] , "3B");
 

 //Open the app, workbook and worksheet
 xclChk(ExcelRpt_ApplicationNew(1, &applicationHandle));
 xclChk(ExcelRpt_WorkbookOpen (applicationHandle , strFnameOut, &workbookHandle));
 xclChk(ExcelRpt_GetWorksheetFromName (workbookHandle, "State Data", &wsHnd_StateData ));

 //Write the labels
 //The single value cell version works
 xclChk(ExcelRpt_SetCellValue (wsHnd_StateData, "N2", CAVT_CSTRING, strModuleLabels[0]));
 
 //The following line gives general protection fault - why?
 xclChk(ExcelRpt_WriteData( wsHnd_StateData, "N3:N8", CAVT_CSTRING, 6, 1, &strModuleLabels[0]));

 xclChk(ExcelRpt_WorkbookSave (workbookHandle, NULL, 0));
 xclChk(ExcelRpt_ApplicationQuit (applicationHandle));

 

ExcelErr:   
 if (HResult)
 {
  CA_GetAutomationErrorString(HResult, strDir, sizeof(strDir));
  MessagePopup("Excel Error" , strDir);
 }
 return iExcelResult;
} //End Function: SaveDataToExcel

0 Kudos
Message 1 of 5
(2,765 Views)

Hi jkin00,

 

Have you looked at any onf the examples that we ship with CVI? One of them show you how to do exactly what you want to do. It is called excalreportdemo.cws. Take a look at it.

 

Regards,

 

Perry S.

Applications Engineer
National Instruments
0 Kudos
Message 2 of 5
(2,759 Views)

Perry,

Thanks for your relpy.  I did actually start with that example.  Unfortunately it uses  ExcelRpt_WriteDataFromTableControl instead.  I don't have a table to write from - just an array of strings.

0 Kudos
Message 3 of 5
(2,754 Views)

Hi jkin00,

 

I have been working on recreating your issue and then finding a solution for it. I was successful on both accounts. I found that the data type input for the ExcelRpt_WriteData function was expecting a char *[ ][ ] while I was only giving it a char [ ][ ]. Also the dimentions of your variable need to match those used in the function. Here is some example code that works.

 

char *myStrings[3][1];
myStrings[0][0] = "Howdy";
myStrings[1][0] = "Sup";
myStrings[2][0] = "Dude";
			
ExcelRpt_ApplicationNew (VTRUE, &applicationHandle);
			
ExcelRpt_WorkbookNew (applicationHandle, &workbookHandle);
			
ExcelRpt_WorksheetNew (workbookHandle, 1, &worksheetHandle);
			
ExcelRpt_WriteData (worksheetHandle, "B1:B3", ExRConst_dataString, 3, 1, myStrings);

 

I hope that this helps.

 

Regards,

 

Perry S.

Applications Engineer
National Instruments
Message 4 of 5
(2,741 Views)

Thanks a lot, that fixed my problem!

0 Kudos
Message 5 of 5
(2,728 Views)