12-13-2010 06:13 AM
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
12-13-2010 07:08 AM
Hi David,
have you seen my answer here? Did you find any problem in implementing Mert's suggestion linked there?
12-13-2010 07:20 AM
Hi Roberto,
Thank you very much, that is what I need.
David
12-13-2010 08:31 PM
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
12-14-2010 06:03 AM
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);
12-14-2010 06:34 AM
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
07-20-2011 10:40 AM
Hello,
may you say to me where can i find the function ExcelRpt_GetCellValue? in which library?
Thank you
07-20-2011 10:59 AM
you need to load the instrument driver excelreport.fp in toolslib\activex\excel
07-21-2011 03:08 AM
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