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.
Related
I have been looking into trying to manipulate an excel document using C++. Basically what I want to do is access an excel document and copy a specified line from that document to the windows clipboard.
I haven't found any libraries I am able to use or any commands I can use to accomplish this task. If anyone can point me to any documentation or examples that show me how to get this accomplished it would be much appreciated.
You can do so using Excel's COM object. Microsoft provides examples in all their languages, here's one in C++
http://support.microsoft.com/kb/216686
And another, more recent one also from Microsoft
http://blogs.msdn.com/b/codefx/archive/2012/03/17/sample-of-mar-17th-excel-automation-in-c-c-and-vb.aspx
It's not an easy subject, the interfaces offered are quite extensive, but it's quite popular and thus lots of examples and reading material can be found.
EDIT: do you have to do this in C++? Because you can do exactly the same thing using the same COM object but using Powershell. Have a look here
http://blogs.technet.com/b/heyscriptingguy/archive/2006/09/08/how-can-i-use-windows-powershell-to-automate-microsoft-excel.aspx
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.
Since time immemorial I've been trying to avoid printing from my Windows-based applications due to the lack of native support for it. Whenever absolutely necessary I was resorting to dynamically making a simple HTML layout and then opening it in a web browser with a short Java Script in it to pop up a printing dialog for a user. Now I need to find something more substantial.
Let me explain. I have a project that deals with medical charts and it has to be able to print into those charts (at specific locations) as well as print on to a Letter/A4 size page in general. It also has to provide a preview of what is being printed in a paged-view environment.
In light of that I was wondering what is available from MFC/C++ environment (not C#) in regarding to printing?
PS. I was thinking to look into the RTF format but that seems like quite a daunting task, so I was also wondering, is there any libraries/already written code that can allow to compose/view/print RTFs? If not, what else is out there that can provide printing support like I explained above?
"lack of native support"? It's been covered by Petzold since forever, and it's integrated straight into GDI. Compared to UNIX, it's a complete breeze. And MFC makes it even easier.
Anyway, here's how you do print preview with MFC, and here's how you subsequently print. Lots of links from there, and it's all straightforward. Printers are just another Device Context on which you can draw.
I always found it very convenient to generate PDF files from my MFC/C++ application, There are many libraries out there which enable easy creation of PDF files, preview functionality and so on (also open source). I'm using this (also handles RTF):
PDF Library
There is no support like you call a framework method with some parameters and the framework prints a document or the content of a window for you. You need to manually draw everything on the printing device context. So as already said, you might find it more convenient to use a PDF generator, but of course that depends on your application requirements.
Please try www.oxetta.com , it's a free report builder solution that easily integrates into a C/C++ application.
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.
I am new to using Windows Forms in C++ (and just in general), and I am not exactly sure of the name or if it's even possible to do.
Currently I am currently working on a school project in which we must make a program for an imaginary bookstore. I am trying right now to make a sort of list that shows what the "customer" is buying. I have to make it sort by price and ISBN and any other variable that the book has.
In essence I am trying to make something like the following:
I just need to know how to get started. I can't figure out what the name of the control is or how to even get it to sort every time the user clicks on the header.
You need to write a managed C++
Please look at
http://www.codeproject.com/KB/miscctrl/mfcandwindowsforms.aspx?fid=3422&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=2509859
Try to do your control same way.
The WindowsForms control you are looking for is called a DataGrid
It's not entirely clear by your question, but if you are trying to access Windows Forms from standard c++ you are out of luck. Windows Forms lives in the Managed world while c++ is unmanaged. To use windows forms you'd have to switch to C++/CLI or C#. Which if you are doing something for a school project may not be an option.
If it is an option to switch languages like that. I'd start looking at C++/CLI documentation to get a feel for how things might work for you.
If you want to know Windows UI inner workings, I recommend you to stay away from .NET for now, and learn some basic things in C++ and WinAPI. Sometimes programming .NET (or C++ / COM) requires you to invoke unmanaged components/functions and you'll be glad you understand how the low-level things work.
If your project requires .NET, go on, but don't forget to make yourself some time to learn good-old Win32 / C++ programming.
Please give some more details about the question Dalze->
is there any requirement about using managed controls? or not using them?
What's your prof want you to learn from this exercise (and is how to use stack overflow to do your homework one of them)?
There's several ways to skin this cat.
If you are supposed to or want to used managed code:
DataGrid mentioned is a good simple database tool link text
An sql database could also hold all the information and allows sorting on the various sub elements.
If you choose not to use managed code you can build a few simple objects to carry the information you need, then add some sort functions for each of the variables of interest.