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
Related
I'm looking for a way of editing and save a specified cell in Excel 2010 .xlsx file from Node.JS. I realize, that maybe there are no production-ready solutions for NodeJS at this time. However, NodeJS supports C++ libraries, so could you suggest me any suitable lib compatible with Node?
Also, I had an idea to process this task via Python (xlrd, xlwt) and call it with NodeJS. What do you think of this? Are there any more efficient methods to edit XLSX from NodeJS? Thanks.
Basically you have 2 possibilities:
node.js does not support C++ libraries but it is possible to write bindings for node.js that interact with a C/C++ library. So you need to get your feet wet on writing a C++ addon for the V8 (the JavaScript engine behind node.js)
find a command line program which does what you want to do. (It does not need to be Python.) You could call this from your JavaScript code by using a child-process.
First option is more work, but would be result in faster executing time (when done right). Second possibility is easier to realise.
P.S.: To many question for one question. I've no idea about the xls-whatever stuff, besides it's "actually" only XML.
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.
I have found how one can write an odf file, but did not found any natively supported by Qt methods that allow to read. Is it possible at all? A small example will be useful.
While you are told you cannot use external libraries, this is something that various companies (Nokia and SKF for example) are successfully using the Callibra engine to do. They are based on Qt, so may perhaps be an option for you. www.calligra.org has a good few bits of information on it :)
There isn't anything in Qt for this.
If you need to manipulate office documents from an application, you could look at using OpenOffice / LibreOffice in server mode controlled via the UNO bridge system. See the OpenOffice.org Developer's Guide for details. Note: this is not trivial to get working correctly.
For as far as I'm aware, this functionality does not exist natively within Qt. There have been requests in the past and there has been mention of ongoing work to read ODF back in 2008, but nothing has been done with this so far to my knowledge.
Perhaps, based on the sources of QTextDocumentWriter for the ODF format, you could fashion your own solution. But I'm not sure how feasible this is. Looking at the sources of QTextOdfWriter, it seems doable, but just a lot of work.
What solutions are there? I know only solutions for replacing Bookmarks in Word (.doc) files with Apache POI?
Are there also possibilities to change images, layouts, text-styles in .doc and .ppt documents?
I think about replacement of areas in Word and PowerPoint documents for bulk processing.
Platform: MS-Office 2003
What are your platform limitations?
Obviously Apache POI will get you at least part of the way there.
Microsoft's own COM API's are fairly powerful and are documented here. I would recommend using them if a) you are not running in a server (many users, multithreaded) environment; b) you can have a proper version of powerpoint installed on the production machine; and c) you can code against a COM object model.
It's a bit pricey, but Aspose.Slides is a very powerful library for manipulating PowerPoint files
If you include using other Office suits as an option, here's a list of possible solutions:
Apache POI-HSLF
PowerPoint 2007 APIs
OpenOffice.org UNO
Using POI you can't edit .pptx file format, but you don't depend on the apps installed on the system. Other two options, on the contrary, make use of other apps, but they are definitely better for dealing with presentations. OpenOffice has better compability with older formats, by the way. Also if you use UNO, you'll have a great choice of languages, UNO exists for Java, C++, Python and other languages.
My experience is not directly with Power Point, but I've actually rolled my own WordML (XML) generator. It a) removed all dependencies on Word, b) was very fast c) and let me build up documents from scratch.
But it was a lot of work to create. And I was only creating a write only implementation.
I'm not as familiar with Power Point, so this is conjecture, but you may be able to roll your own by reading XML (Power Point 2003??) and/or cracking the Office Open XML file (zipped XML), then using XPath to manipulate the data, and then saving everything back to disk.
This won't work on older OLE Compound Document based Power Point files though.
I've done something like that before: programmatically accessed and manipulated PowerPoint presentations. Back when I did it, it was all in C++ using COM, but similar principles apply to C#/VB .NET apps, since they do COM interop very easily.
What you're looking for is called the Office Document Model. Basically, Office applications expose their documents programmatically, as trees of objects that define their contents. These objects are accessible via an API, and you can manipulate them, add new ones, and do whatever other processing you want. It's exceedingly powerful; you can use it to manipulate pretty much all aspects of a document. But you'll need an installation of Office and Visual Studio to be able to use it.
Some links:
Intro: http://msdn.microsoft.com/en-us/library/d58327k6.aspx
Hope this helps!
Apparently new users can only include one link per posting. How lame! :)
Here's the other link I meant to include:
Example of manipulating PowerPoint documents programmatically: http://msdn.microsoft.com/en-us/library/cc668192.aspx
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.