Turning a DLL (and associated VBA) into an XLL - c++

As a summer project, I got handed a large C++ file with numerous (over 50) functions and was asked to make it interface with Excel. I created a DLL from the C++ file and wrote some VBA procedures to create function wrappers, function wizards, and populate cell ranges with the correct data.
As I have to hand this off to someone else, I would like to turn this into an XLL add-in so the pathway to the DLL in the VBA "Declare Function" doesn't get broken, as well as having a cleaner setup.
My question is, what becomes of the VBA code in the process of turning this into an XLL add-in? Do those functions have to be re-written into the C++ file?
Chris

The XLL interface does not cover as much of the Excel object model as VBA, and is less productive for user interface tasks. But it has many advantages over VBA for building UDFs (performance, UDF registration, multithreading etc).
So my recommendation would be to convert all the UDFs to XLL but keep the function wizards and any other user interface stuff in a VBA XLAM.

Related

Transform Excel VBA in a Web-Service function

I am working on a project, that has Excel VBA code.
We need to execute the VBA code concurrently (Excel has not be modified between executions).
NOTE: The VBA code is called by another system.
Goal: transform Excel VBA code in a web-service function
The first idea was put the Excel on Sharepoint, but this is not a choice as we can see on: http://community.office365.com/en-us/w/officeapps/excel-workbooks-with-macros-do-not-open-in-excel-online/revision/2.aspx
Is Excel Calculation Services our solution? I never heard about that
https://technet.microsoft.com/es-es/library/cc263457%28v=office.12%29.aspx
Another option without Excel: discard the Excel and construct the Web-Service logic in an OOP language (like Java), the only trouble about that is the reverse engineering on a very complex Excel.
This really depends on your circumstances, its true that VBA won't work in a web view of an excel file on sharepoint, but if you open the file in excel the VBA macro should work fine.
If the macro needs to access network resources via sharepoint where you don't have webDAV access to the share then its more tricky but can be done.
Can you clarify your situation.

How to get C++ to interact with the menus of a windows program/ how to get C++ to fully control another program

I am trying use C++ to automate the production of PDFs followed by transferring them into an Excel worksheet and formatting the information (Data Mining).
I am able to open/run the 3rd party program using C++ CreateProcess() or System().
But I am unable to interact with the menu of the program to import data and produce PDFs.
I have been stuck for 2 days (C++ novice) but I have done a lot of searching so I think it can be done.
Three quick questions:
Is C++ the best way to create an executable to accomplish this?
How would one get C++ (or a more recommended language) to talk to an opened program? (It is not a Microsoft program, it's an individually developed program). Once I get this I should be able to use C++ to talk to Excel and finish the job using a macro.
Out of curiosity, is there a way to accomplish all of this just by using an Excel macro? I know Excel can copy data from a PDF, but I am not sure if it can interact with another program to produce the PDFs.
Thanks a lot in advance. I really really really need your help.

I want to create a DeskBand. Do I have to use C++?

I want to create a DeskBand to display some information on my Windows task bar, but I am struggling with implementing the functionality I need in C++. It's been about 10-15 years since I touched C++. I've been working entirely in .NET for the past 7 years.
Before you say it - I know that DeskBands are deprecated. But the suggested replacement UI element - thumbnail toolbars - don't meet my needs. I need a UI element that is constantly visible to the user no matter which application they switch to, and also that provides enough room to display a line of text - I could get by with room for 30 characters or so.
I've been able to get the DeskBand from the Windows SDK sample to compile and run, but now I need to implement some real functionality - specifically...
Locating the AppData\Local folder (SHGetKnownFolderPath(FOLDERID_LocalAppData...)
Watching an XML file for modifications. I need to parse and repaint whenever the file changes.
Parsing the XML file (I found pugixml)
Displaying some data from the XML file in my DeskBand
Setting a timer to repaint the DeskBand once per minute
... and I am realizing how little I know about C++, and how much I've come to depend on .NET's Base Class Library. This task would be super easy for me if I was writing it in C#. But I've learned elsewhere that you shouldn't write shell extensions in .NET.
What are my options? Is there an easier language to accomplish this in - maybe Python? Or do I have to just bite the bullet and do this in C++? If so, any advice for a .NET developer trying to implement a WinAPI shell extension in C++?
Thank you in advance.
Shell Extensions are COM objects, and C++ is generally the best language to use when developing COM objects because COM was designed primarily for C++, but it is not the only language possible. COM has a standardized architecture, so you can use any language outside of .NET that supports COM object development (Delphi, VB, etc) to develop Shell Extensions (similar to how the Win32 API is primarily designed for C, but any C-compatible language can access it).

Making charts in excel programmatically

I have an XLL made with the help of the XLW wrapper for Excel's C API. I would like to be able to programmatic make charts in excel using data stored in some objects in the XLL. Is this possible and if so, what is the best way to do it? I believe one way to do is through COM but would like to avoid it if at all possible.
Currently using Excel 2007 on Windows 7 and VS2010.
Edit: In general what API does excel expose that supports programmatic charting? Can anyone point me towards some documentation?
Edit2: Since I'm not getting any hits I will try to give a little more detail abaout what I'm trying to do. I want to call a formula from Excel like =PlotCurve("CurvreHandle") and I want to get a curve object stored in memory and owned by the XLL (unmanaged code), get an some data from it and display it in a chart somewhere on the sheet where the PlotCurve was made. From what I have been able to gleam so far, the C API that XLW is wrapping offers no support for the second part of the problem so I need to go to either COM (which I have no idea how to mix with the already running C api) or some .net interop which I also don't know how to do . If someone has ever done something like this or knows of a safe and stable way to do this, I would love to hear it.
You can use http://xll.codeplex.com and Excel4/Excel12. The function ExcelX can be used to handle the memory management. The command to use is xlcChartWizard.
To create, modify, save charts in Excel programmatically you can use the C++ classes in the Microsoft.Office.Interop.Excel namespace.

best way to programmatically modify excel spreadsheets

I'm looking for a library that will allow me to programatically modify Excel files to add data to certain cells. My current idea is to use named ranges to determine where to insert the new data (essentially a range of 1x1), then update the named ranges to point at the data. The existing application this is going to integrate with is written entirely in C++, so I'm ideally looking for a C++ solution (hence why this thread is of limited usefulness). If all else fails, I'll go with a .NET solution if there is some way of linking it against our C++ app.
An ideal solution would be open source, but none of the ones I've seen so far (MyXls and XLSSTREAM) seem up to the challenge. I like the looks of Aspose.Cells, but it's for .NET or Java, not C++ (and costs money). I need to support all Excel formats from 97 through the present, including the XLSX and XLSB formats. Ideally, it would also support formats such as OpenOffice, and (for output) PDF and HTML.
Some use-cases I need to support:
reading and modifying any cell in the spreadsheet, including formulas
creating, reading, modifying named ranges (the ranges themselves, not just the cells)
copying formatting from a cell to a bunch of others (including conditional formatting) -- we'll use one cell as a template for all the others we fill in with data.
Any help you can give me finding an appropriate library would be great. I'd also like to hear some testimonials about the various suggestions (including the ones in my post) so I can make more informed decisions -- what's easy to use, bug-free, cheap, etc?
The safest suggestion is to just use OLE. It uses the COM, which does not require .NET at all.
http://en.wikipedia.org/wiki/OLE_Automation <--about halfway down is a C++ example.
You may have to wrap a few functionalities into functions for usability, but it's really not ugly to work with.
EDIT: Just be aware that you need a copy of Excel for it to work. Also, there's some first-party .h files that you can find specific to excel. (it's all explained in the Wikipedia article)
I don't know if this is an option for you, but the new office 2007 formats are in zipped XML format, which makes it very doable to do your own modifications. See here for the specifications.
SpreadsheetGear for .NET will handle your requirements and has an API which is very similar to Excel.
When you insert cells, your defined names (and any other formulas / charts / etc...) will automatically be fixed up to reference the new range (just as they would in Excel). So you would not need to update your defined names (although there is complete support for creating and updating defined names if that is what you want to do).
SpreadsheetGear is a .NET component, but you can build your own wrapper which is callable from C++.
You can see what our customers say and download the free, fully functional evalution here.
Have you already tried using the Excel COM interfaces? Obviously Excel needs to be install on the machine, and it's a pain to deal with...
I would argue that a .net solution with COM interop for linking into your C++ application is the best solution. In more than ten years of working with them, I've never seen a COM automation of Excel that didn't leak memory somewhere.
If you need to automate Excel, I recommend Visual Studio Tools for Office. If you don't need to automate, only modify files and those files can be in Office 2007 format, you're better off finding a library that manipulates the files directly instead of opening Excel to do it.
I ended up using Aspose.Cells as I mentioned in my original post, since it seemed like the easiest path. I'm very happy with the way it turned out, and their support is very good. I had to create a wrapper around it in C# that exported a COM interface to my C++ application.