08-09-2012 05:13 PM
I am not able to get the Excel_RangeAutoFit function to work.
Here is an edited code section I am running. All the lines work except the last one.
/* Select columns A to L and autoformat column width */
CA_VariantSetEmpty (&CellRangeV);
CA_VariantSetCString (&CellRangeV, "A:L");
errorCode = Excel_WorksheetActivate (ws_handle, NULL);
errorCode = Excel_WorksheetRange (ws_handle, &ErrorInfo, CellRangeV, CA_DEFAULT_VAL, &rangeHandle);
errorCode = Excel_RangeActivate (rangeHandle, &ErrorInfo, &axStatus);
errorCode = Excel_RangeSelect (rangeHandle, &ErrorInfo, &axStatus);
/* this line errors out */
errorCode = Excel_RangeAutoFit (rangeHandle, &ErrorInfo, &axStatus);
Thanks
08-10-2012 08:28 AM
I have never seen a Range object selected with A:L
http://msdn.microsoft.com/en-us/library/bb178282%28v=office.12%29.aspx
08-10-2012 11:03 AM
I also tried selecting it with a fully defined range as (A1:L50).
That did not work either.
I am just trying to auto size a set of columns.
Any other command to do this?
08-10-2012 12:04 PM
Are you obtaining a value for ws_handle elsewhere in your code?
If it was me, I would have just
CA_VariantSetEmpty (&CellRangeV);
CA_VariantSetCString (&CellRangeV, "A1:L50");
errorCode = Excel_WorksheetRange (ws_handle, &ErrorInfo, CellRangeV, CA_DEFAULT_VAL, &rangeHandle);
errorCode = Excel_RangeAutoFit (rangeHandle, &ErrorInfo, &axStatus);
08-10-2012 12:51 PM
Yes I do get the handle to the worksheet.
As a work around I am sucessfully sending this to fix the columns at a specific size:
errorCode = Excel_SetProperty (rangeHandle, &ErrorInfo, Excel_RangeColumnWidth, CAVT_VARIANT, CA_VariantDouble(16.86));
So, I know the rangeHandle and ws_hadle are valid.
Thanks
JC