LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Which function can be used to read string data from Excel cell?

I have test the excel2000dem in the activex fold, but this example just tell how to read the double type data from the excel cell, I'd like to know which function can be used to read string type data from the cell?

 

 

Thanks

 

David

0 Kudos
Message 1 of 9
(4,918 Views)

Hi David,

have you seen my answer here? Did you find any problem in implementing Mert's suggestion linked there?



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 Kudos
Message 2 of 9
(4,910 Views)

Hi Roberto,

 

Thank you very much, that is what I need.

 

David

0 Kudos
Message 3 of 9
(4,904 Views)

Hi Roberto,

 

As Mert's suggestion, it seems the excel doc's rows must should be knowing, that can use char *AColumnExcel[2000] to allocate the corresponding spaces. but if the excel doc. rows is unable knowing beforehand, I think it shoud using "char **AColumnExcel;" to express, in this case, how should I to process?

 

 

David

0 Kudos
Message 4 of 9
(4,877 Views)

Hi David, as far as I can see the system already allocates the exact memory space needed to retrieve range values an no more than this.

Let's explain things this way: when you dimension a variable of type char *AColumnExcel[2000] you are creating a string array capable of 1000 elements, but no space is actually allocated excepct for the few bytes needed for the pointers.

ExcelRpt_ReadData function effectively allocates memory space for the string representation of cell contents, i.e. rows * cols elements of the array (depending on the cell range you have passed to the function) each of them with proper size. This can be seen in the variable screen if you add a breakpoint immediately after the function call. This is why you need to free the strings after you have finished using them.

In any case, you can dynamically allocate the initial array before passing it to ExcelRpt_ReadData this way (reading a range of 12 cells):

 

    char    **buf = NULL;

    buf = malloc (12 * sizeof (char *));
    error = ExcelRpt_ReadData (worksheetHandle, "B2:C7", ExRConst_dataString , buf);


    for (i = 0; i < 12; ++i) {
        DebugPrintf ("Row %d: %s (%d bytes)\n", i, buf[i], strlen (buf[i]));
        CA_FreeMemory(buf[i]);
    }
    free (buf);



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 Kudos
Message 5 of 9
(4,847 Views)

Just to clarify a typo in Roberto's post:


@Roberto Bozzolo wrote:

 when you dimension a variable of type char *AColumnExcel[2000] you are creating a string array capable of 1000 elements, but no space is actually allocated excepct for the few bytes needed for the pointers.


This actually creates 2000 pointers, which is probably not what was intended. A similar statement, but without the '*', is probably more suitable for reserving a known amount of space at compile time: char AColumnExcel[2000];, but how appropriate this is depends on your application.

JR

0 Kudos
Message 6 of 9
(4,842 Views)

Hello,

 

may you say to me where can i find the function ExcelRpt_GetCellValue? in which library?

 

Thank you

0 Kudos
Message 7 of 9
(4,448 Views)

you need to load the instrument driver excelreport.fp in toolslib\activex\excel

0 Kudos
Message 8 of 9
(4,445 Views)

Wolfgang Thank you so much!

 

Now everything works fine, I'm new to LabWindows/CVI and this site helped me alot, especially your very well-timed answer.

 

Thanks,

 

Marco

0 Kudos
Message 9 of 9
(4,433 Views)