LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Trasfering an array of strings into Excel

Hi.

My aplication needs to speed the opperations. So I have to implement a data transfer between my application and Excel.
I read the example excel2000dem but it shows how to work with double data. I need to transfer in Excel an array of strings.
In the example every cell contain a number and I need to put a word. Until now I transfer my data into excel cell by cell, and it takes too many time.

I looked for a function that can build an array of strings fot the transfer into excel and I find CA_VariantSetBSTR.
Can I do that with this function? Is there another way? If I build my array of strings into a safe array what function can
I use to transfer the data in Excel.


Thanks.
0 Kudos
Message 1 of 2
(2,747 Views)
Hello Tmaxial,

As you mentioned in your post, you would use Method 3 in the WriteDataToExcel callback in the exceldemo2000 example program. For each string in your array, you would convert it to a BSTR with the CA_CStringToBSTR function. Then, you would save all your BSTRs in one VARIANT array using the CA_VariantSetBSTR function. Then, you would convert the VARIANT array into a SAFEARRAY, then store the resulting SAFEARRAY as a VARIANT using the CA_Array2DToSafeArray and CA_VariantSetSafeArray functions. From there, you can assign values to multiple excel cells at one time using the Excel_SetProperty function.

So a section of the modified write callback would look something like:

#define ROWS 2
#define COLUMNS 2
char * excelString[] = {"String 1", "String 2", "String 3", "String 4"};
BSTR bstring;
...
for (i=0;i lessthan ROWS;i++)
{
for (j=0;j lessthan COLUMNS;j++)
{
CA_CStringToBSTR (excelString[i*COLUMNS+j], &bstring);
error = CA_VariantSetBSTR (&vArray[i*COLUMNS+j], bstring);
}
}
...

Where "lessthan" should be replaced with the left carat sign.

Hope that helps.
Message 2 of 2
(2,732 Views)