07-10-2010 07:16 PM
I'm trying to read a range of cell values in a single row using ExcelReport instrument in CVI 2009.
I have a cell in TIME format that I don't see that I can read except as a string? I also have several INT values that I can only read as individual cells, not as a range?
I have created an elapsed time as a "TIME" formatted cell but how can I programmatically read it?
And it looks to me that reading a range of cells as ints isn't possible? What's up with that? Are these limitations of a simplistically implemented Excel Report, or is it a limitation of the MS Excel autmation interface?
I have a bad feeling about Excel Report.
Menchar
07-11-2010 04:50 PM
Another aspect of this is how can I use the R1C1 style of cell references?
I set the cell reference format to a workbook to be the "R1C1" style, and when I run Excel and load the workbook, it does indeed display in R1C1 format.
BUT when I use R1C1 format in ExcleRpt_GetCellValue it reports an exception error, and will not allow R1C1 cell references, while allowing A1 style references.
ExcelReport appears to be almost unusable for the simple task of programmatically getting and setting cell values without running into the issue of getting an alpha column reference.
I suppose I could write a function that creates the alphabetic column reference from an ordinal column number, but this seemes especially stupid given that Excel is designed to allow R1C1 references, but ExcelRpt won't work with them for some reason.
Does anyone know a way around this?
Thanks for any help on this.
Menchar
07-11-2010 05:13 PM
I can't win for losing ...
I successfully set the Excel to use reference type R1C1 using
iStatus = Excel_SetProperty (hExcel, NULL, Excel_AppReferenceStyle, CAVT_LONG, ExcelConst_xlR1C1);
and in fact if I make Excel visible I can see the columns showing numeric R1C1 format, so I know that the R1C1 reference style is in effect.
BUT when I use "R1C1" as the cell reference in ExcelRpt_GetCellValue I still get an exception error, and "A1" references still work with no error - it's as if the reference property was never changed.
Pretty weird, huh.
Menchar
07-12-2010 07:19 AM
@menchar wrote:
I suppose I could write a function that creates the alphabetic column reference from an ordinal column number
That's what I do - sometimes you just have to do what works. Here's a simple function:
// Make an Excel range string from zero-based cell coordinates. // Width, Height should each be >=1 char *RangeString(int left, int top, int width, int height) { static char retVal[20]; char col1[4]; char col2[4]; if (left<26) { col1[0] = left+'A'; col1[1] = '\0'; } else { col1[0] = (left/26)-1+'A'; col1[1] = (left%26)-1+'A'; col1[2] = '\0'; } if ((width<=1)&&(height<=1)) { sprintf(retVal,"%s%d",col1,top+1); return retVal; } left += width-1; if (left<26) { col2[0] = left+'A'; col2[1] = '\0'; } else { col2[0] = (left/26)-1+'A'; col2[1] = (left%26)-1+'A'; col2[2] = '\0'; } sprintf(retVal,"%s%d:%s%d",col1,top+1,col2,top+height); return retVal; }
07-13-2010 11:02 AM
Martin -
Thanks for the code.
Sure, you can always hack out little solutions to these things, but it adds up when you keep encountering them. I find that when I develop an app, much of my time is spent running things like this to ground rather than devleoping the app itself.
Thanks again for the code,
Menchar