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:
//Dummy labels for now...
strcpy(strModuleLabels , "1A"); //These labels will come from
strcpy(strModuleLabels , "2A"); //different source when
strcpy(strModuleLabels , "3A"); //the Excel code is working
strcpy(strModuleLabels , "1B");
strcpy(strModuleLabels , "2B");
strcpy(strModuleLabels , "3B");
//Open the app, workbook and worksheet
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));
//The following line gives general protection fault - why?
xclChk(ExcelRpt_WriteData( wsHnd_StateData, "N3:N8", CAVT_CSTRING, 6, 1, &strModuleLabels));
xclChk(ExcelRpt_WorkbookSave (workbookHandle, NULL, 0));
CA_GetAutomationErrorString(HResult, strDir, sizeof(strDir));
MessagePopup("Excel Error" , strDir);
} //End Function: SaveDataToExcel
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.
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.
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; myStrings = "Howdy"; myStrings = "Sup"; myStrings = "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.