通过xll中的xlcFormatNumber设置Excel数字格式
时间:2020-03-05 18:55:28 来源:igfitidea点击:
我正在尝试设置单元格的数字格式,但对xlcFormatNumber的调用失败,将单元格数字格式保留为"常规"。我可以使用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 = "#.00"; //I've tried various formats Excel4( xlcFormatNumber, &xRet, 2, (LPXLOPER)&xRef, (LPXLOPER)&xFormat);
我没有找到有关此命令用法的任何文档。在这里的任何帮助将不胜感激。
解决方案
回答
感谢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);