如何调用“Open XML Format SDK”来自Borland C ++。 [英] How to call "Open XML Format SDK" from Borland C++.

查看:74
本文介绍了如何调用“Open XML Format SDK”来自Borland C ++。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从Borland C ++调用Open XML Format SDK来创建XLSX格式的文件。

有没有人有例子怎么做?



谢谢

I need to call "Open XML Format SDK" from Borland C++ to create file in XLSX format.
Does anybody has example how to do this?

Thanks


推荐答案

Open XML SDK适用于.NET 。要将它应用于C ++,您需要在C ++ / CLI或C#中编写一些映射代码,这需要在.NET中进行更多限定,然后编写.NET应用程序。这已经失败了将Open XML SDK暴露给非托管代码的目的。



但接下来的步骤更加困难。当我说映射代码时,我的意思是创建OOP SDK的非OOP包装器。可能在C ++方面,您需要包装C ++类。这样一个棘手的OOP thunk。这就是为什么它需要非平凡的资格。但接下来的步骤更难?事情就是这样:.NET没有很好地将托管代码导出到非托管(相反,在.NET中使用非托管代码要简单得多,技术和工具称为P / Invoke,但仍然不容易使用)。您可以使用一些技术技巧,其中一个是将.NET暴露给COM,另一个是直接导出到非托管,这需要非常特殊的.NET编程。请查看我过去的答案:

加载C# MFC中的DLL [ ^ ],

如何在Visual Basic 6.0中使用Visual Basic 2008中创建的dll [ ^ ],

调用托管DLL编写在C#中来自Unmanged Code VC ++ [ ^ ],

API在.Net:托管代码或非托管代码 [ ^ ]。



你还觉得你想进入那个吗?我无法想象它。 Open XML SDK用于操作Microsoft Office文档。在.NET中完成这项工作(并将.NET学习到可以完成此类工作的水平)可能并不容易。但是,要使用C ++实现它的本机C ++包装器,需要学习更高级别的.NET。另外,你肯定会使用丑陋的C ++包装器,很可能充满了bug,因为所有非常重要的工作(请注意,如果上述所有内容都不够,那么在常规单平台上调试要困难得多)编程)引入新的bug,特别是如果这项工作很难。



我希望你能得出结论,任何将这个SDK暴露给非托管C ++的尝试都没有任何实际意义。



-SA
Open XML SDK is for .NET. To apply it to C++, you will need to write some mapping code in C++/CLI or C#, which would require more qualification in .NET then writing .NET application. This already could defeat the purpose of exposing Open XML SDK to unmanaged code.

But next steps are even more difficult. When I say "mapping code", I meant creation of an non-OOP wrapper of the OOP SDK. Probably, in C++ side, you will need to wrap in C++ classes. Such a tricky "OOP thunk". That's why it requires non-trivial qualification. But what next steps are more difficult? Here is the thing: .NET is not well designed to export managed code to unmanaged (the opposite, using unmanaged code in .NET is much simpler, the technique and the facility is called "P/Invoke" and still not at all easy to use). You could use some technical tricks, one of then is exposing .NET to COM, and another one is direct export to unmanaged which required very special .NET programming. Please see my past answers:
loading C# DLL in MFC[^],
How can I use a dll created in Visual Basic 2008 in Visual Basic 6.0[^],
Call Managed DLL written in C# from Unmanged Code VC++[^],
API's in .Net: Managed or UnManaged Code[^].

Do you still feel that you want to get into that? I cannot imagine it. Open XML SDK is used to manipulate Microsoft Office documents. Doing this work in .NET (and learning .NET to the level when you can do such work) maybe not very easy. But, to make your "native C++ wrapper" to do it in C++ will require you to learn .NET to much higher level. Plus, you would be bound to using ugly C++ wrapper, very likely full of bugs, because all non-trivial work (mind you, if all of the above was not enough, debugging is much more difficult then in "regular" single-platform programming) introduce new bug, especially if this work is difficult.

I hope you can conclude that any attempt to expose this SDK to unmanaged C++ would make no practical sense.

—SA


最好的方法可能是制作一个C ++ / CLI包装器会在内部使用SDK,但会提供更高级别的特定于您的应用程序的界面。



因此大多数复杂性都在托管代码中,您可能会调试ansd从托管测试应用程序测试它。一旦这些高级函数工作,那么你可能会暴露它们。



正如在第一个解决方案中提到的,这不是微不足道的,取决于你的问题Open XML SDK可能不是最佳方案。 SDK的级别非常低,因此需要了解很多细节。如果目标文档相对简单,那么从SDK附带的工具生成大多数托管代码可能相对容易....但只要您希望文档非常动态(内容或样式),它就是很多作品。



根据您在SDK或托管代码方面的能力和经验,您想要考虑的复杂性和预算,您需要考虑第三方替代方案。
The best way would probably be to make a C++/CLI wrapper that would use the SDK internally but present a much higher level interface that is specific for your application.

Thus most of the complexity would be in managed code and you might be able to debug ansd test it from a managed test application. Once those high levels functions works, then you might expose them.

As mentionned in first solution this is not trivial and depending on your problem Open XML SDK might not be the best solution. The SDK is very low level so it require to understand a lot of details. If the target document is relatively simple, then it might be relatively easy to generate most managed code from Tools that come with the SDK.... but as soon as you want your document to be very dynamic (content or style), it is a lot of works.

Depending on your competence and experience with the SDK or managed code, the complexity of what you want to do and your budget, you want to consider third party alternatives.


这篇关于如何调用“Open XML Format SDK”来自Borland C ++。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆