c++ - 在 xll 中通过 xlcFormatNumber 设置 Excel 数字格式

标签 c++ excel xll

我正在尝试设置单元格的数字格式,但对 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 = "\4#.00"; //I've tried various formats

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

我还没有设法找到任何关于此命令用法的文档。此处的任何帮助将不胜感激。

最佳答案

感谢 Simon Murphy 的回答:- 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);

关于c++ - 在 xll 中通过 xlcFormatNumber 设置 Excel 数字格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70643/

相关文章:

vba - Multi-Tenancy HANA 数据库的 ODBC 连接字符串

java - 使用 Apache POI 读取/写入同一 Excel 文件

c++ - 有没有办法从 Excel 的公式栏中获取文本和光标位置?

c++ - gcc 中变量模板的错误显式模板特化

C++ : In how many ways compiler optimizes away our code?

excel - 检测到更改时将范围复制到另一个工作表的下一行

python - 在 DLL 中嵌入 Python : Access violation reading location when Py_DECREF list object

c++ - 以编程方式在Excel中制作图表

c++ - Mat 和 Pix 的不同 Tesseract 结果

c++ - 如何在 Windows 8 中以编程方式触发鼠标和键盘事件?