如何为Excel创建xll?

发布于 2024-11-02 14:15:19 字数 1624 浏览 2 评论 0原文

我试图创建一个简单的 xll 文件,但我不能 我已按照 msdn 站点中的教程进行操作 http://support.microsoft.com/kb/178474 但本教程适用于 Microsoft Excel 97 Developer's Kit,我只有 2007 版本 Visual Studio 2005,所以这可能是导致错误的原因:

1>------ Build started: Project: Anewxll, Configuration: Debug Win32 ------
1>Compiling...
1>Anewxll.cpp
1>c:\nam\test\anewxll\anewxll\anewxll.cpp(97) : error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types
1>        c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(5031): could be 'int AfxMessageBox(LPCTSTR,UINT,UINT)'
1>        c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(5033): or 'int AfxMessageBox(UINT,UINT,UINT)'
1>        while trying to match the argument list '(const char [21], long)'
1>c:\nam\test\anewxll\anewxll\anewxll.cpp(140) : error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types
1>        c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(5031): could be 'int AfxMessageBox(LPCTSTR,UINT,UINT)'
1>        c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(5033): or 'int AfxMessageBox(UINT,UINT,UINT)'
1>        while trying to match the argument list '(char [8192], long)'
1>c:\nam\test\anewxll\anewxll\anewxll.cpp(174) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [14]' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

I'm trying to create just a simple xll file but I can not
I've followed the tutorial in the msdn site
http://support.microsoft.com/kb/178474
But this tutorial is for Microsoft Excel 97 Developer's Kit, i just have the version 2007
an visual studio 2005, so this is maybe what cause the error:

1>------ Build started: Project: Anewxll, Configuration: Debug Win32 ------
1>Compiling...
1>Anewxll.cpp
1>c:\nam\test\anewxll\anewxll\anewxll.cpp(97) : error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types
1>        c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(5031): could be 'int AfxMessageBox(LPCTSTR,UINT,UINT)'
1>        c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(5033): or 'int AfxMessageBox(UINT,UINT,UINT)'
1>        while trying to match the argument list '(const char [21], long)'
1>c:\nam\test\anewxll\anewxll\anewxll.cpp(140) : error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types
1>        c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(5031): could be 'int AfxMessageBox(LPCTSTR,UINT,UINT)'
1>        c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(5033): or 'int AfxMessageBox(UINT,UINT,UINT)'
1>        while trying to match the argument list '(char [8192], long)'
1>c:\nam\test\anewxll\anewxll\anewxll.cpp(174) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [14]' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

煞人兵器 2024-11-09 14:15:19

您收到的错误消息与 Excel 或 Excel SDK 无关。前 2 个错误是由于您使用 AfxMessageBox(MFC API)造成的,第三个错误是由于参数与 Win32 消息框 API 不匹配造成的。导致这些错误的原因是您的项目是 Unicode 应用程序(导致 TCHAR 计算为 wchar_t 以及 MessageBox 等宏计算为 MessageBoxW 而不是 MessageBoxA)。最简单的解决方法是将应用程序从 Unicode 更改为 MBCS。

但是 - 如果我可以提出建议 - 考虑使用 Add-in Express 或 ExcelDNA 来创建您的 UDF/RTD。我猜您不太熟悉 Win32 C++ 编程。如果是这种情况,您将在使用纯 C++ 和 Excel SDK 创建 UDF/RTD/Addins 时遇到很多麻烦。

相反,如果您使用插件express或excel dna - 它们会解决将xlopers转换为直观的.net类型和其他各种管道的所有麻烦,让您可以自由地专注于您的业务逻辑。

免责声明:我与 Add-in Express 或 Excel DNA 没有任何关系。我只是碰巧断断续续地使用过它们。

The error messages that you have are not related to Excel or the Excel SDK. The first 2 errors are due to your usage of AfxMessageBox (an MFC API) and the 3rd is because of parameter mismatch with the Win32 message box API. These errors are caused because your project is an Unicode application (causing TCHAR to evaluate to wchar_t and macros such as MessageBox to evaluate to MessageBoxW as opposed to MessageBoxA). The simplest fix would be to change your application from Unicode to MBCS.

However - if I may make a suggestion - consider using Add-in express or ExcelDNA to create your UDF/RTDs. I am guessing you are not very comfortable with Win32 C++ programming. If that is the case you will face a lot of trouble creating UDFs/RTDs/Addins with plain C++ and the Excel SDK.

If instead you go with add-in express or excel dna - they take care of all the headaches of converting xlopers to intuitive .net types and other assorted plumbing, leaving you free to concentrate on your business logic.

Disclaimer: I am in no way associated with either add-in express or excel dna. I have just happened to have used them on and off.

静水深流 2024-11-09 14:15:19

如果您可以安装 MSVC++ 2010 Express,那么 http://xll.codeplex.com 将为您省去很多麻烦。

If you can install MSVC++ 2010 Express then http://xll.codeplex.com willsave you a lot of trouble.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文