Question

I'm trying to set the number format of a cell but the call to xlcFormatNumber fails leaving the cell number format as "General". I can successfully set the value of the cell using xlSet.

XLOPER xRet;
XLOPER xRef;

//try to set the format of cell A1
xRef.xltype = xltypeSRef;
xRef.val.sref.count = 1;
xRef.val.sref.ref.rwFirst = 0;
xRef.val.sref.ref.rwLast = 0;
xRef.val.sref.ref.colFirst = 0;
xRef.val.sref.ref.colLast = 0;

XLOPER xFormat; 
xFormat.xltype = xltypeStr;
xFormat.val.str = "\4#.00"; //I've tried various formats

Excel4( xlcFormatNumber, &xRet, 2, (LPXLOPER)&xRef, (LPXLOPER)&xFormat);

I haven't managed to find any documentation regarding the usage of this command. Any help here would be greatly appreciated.

Was it helpful?

Solution

Thanks to Simon Murphy for the answer:- Smurf on Spreadsheets

//It is necessary to select the cell to apply the formatting to
Excel4 (xlcSelect, 0, 1, &xRef);

//Then we apply the formatting
Excel4( xlcFormatNumber, 0, 1, &xFormat);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top