简体   繁体   English

通过 xll 中的 xlcFormatNumber 设置 Excel 数字格式

[英]Setting Excel Number Format via xlcFormatNumber in an xll

I'm trying to set the number format of a cell but the call to xlcFormatNumber fails leaving the cell number format as "General".我正在尝试设置单元格的数字格式,但对 xlcFormatNumber 的调用失败,将单元格数字格式保留为“常规”。 I can successfully set the value of the cell using xlSet.我可以使用 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.在这里的任何帮助将不胜感激。

Thanks to Simon Murphy for the answer:- Smurf on Spreadsheets感谢 Simon Murphy 的回答:- 电子表格上的蓝精灵

//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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM