如何从C ++代码访问Excel文件单元格 [英] How can I access Cells of Excel file from C++ code
问题描述
我是电气工程师。我正在尝试访问Excel文件,我开始了解'fstream.h'。可以从Excel文件读取或写入数据。但我想访问Excel工作表的任何单个中间单元格并编辑其数据。我还想知道我们如何从C ++环境中执行不同的Excel命令,例如:在excel,粗体命令,斜体命令等上打印命令。
我们非常感谢您对本文的任何帮助。 Thanx。
使用streamio无法读取或写入Excel文件,因为它们的内容采用Microsoft的专有格式或压缩XML。在任何一种情况下,您都需要使用 http://support.microsoft.com/kb/216686 [ ^ ]。如果您了解C#(或C ++ / CLI),那么这是一个更容易的过程,您可以按照使用MS Excel(xls / xlsx)使用MDAC和Oledb [ ^ ]。
< blockquote>你最好的选择是 Excel Automation
(而不是使用 fstream
来读取 Excel
文件:您必须根据 Microsoft
规范解析。
例如,请参阅:
MSDN上的使用C ++进行Office自动化 [ ^ ]。
\"MS Office OLE Automa使用C ++在Code Project [ ^ ]。
Hi, I am Electrical Engineer. I am trying to access Excel files, I've come to know the 'fstream.h'. Data can be read or written from and to Excel Files. But I want to access any single middle cell of Excel sheet and edit its data. I also want to know that how can we execute different commands of Excel from C++ environment, e.g. printing command on excel, bold command, italic command etc.
Any kind of help regarding this article will highly be appreciated. Thanx.
Excel files cannot be read or written using streamio, since their content is in Microsoft's proprietary format, or compressed XML. In either case you need to use the Microsoft interface libraries as described in http://support.microsoft.com/kb/216686[^]. If you know C# (or C++/CLI) then it is a much easier process and you can use OLEDB as described in Working with MS Excel(xls / xlsx) Using MDAC and Oledb[^].
You best bet isExcel Automation
(as opposed to usingfstream
s to readExcel
files: you would have to parse them, based on theMicrosoft
specifications).
See, for instance:
"Office automation using C++" at MSDN[^].
"MS Office OLE Automation Using C++" here at Code Project[^].
这篇关于如何从C ++代码访问Excel文件单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!