Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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
C++

Posted

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
 
Share this answer
 
v4
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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900