C++ 使用C++从excel文件中提取数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7673926/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Extract data from excel file using C++
提问by Tanzila Khan
Can anyone provide me a direct and easy way (ofcourse with codes and other necessary libraries to be included for right execution) to input data from excel file to C++? Actually, I need to input a huge amount of data to input from excel in C++ and finally when computed with C++, linking outputs with excel again. Can anyone help please?
任何人都可以为我提供一种直接而简单的方法(当然,包含代码和其他必要的库以正确执行)将数据从 excel 文件输入到 C++?实际上,我需要输入大量数据以从 C++ 中的 excel 输入,最后在使用 C++ 计算时,再次将输出与 excel 链接。有人可以帮忙吗?
回答by user807566
As others have mentioned, using CSVfiles is the easiest route, as they can be imported/exported to and from Excel. This would likely be the most effective solution because it would require nothing more than the standard C++ libraries and would likely be much faster than using an Excel library. Once you have the CSV file, you can open it in Excel and convert it to a "real" Excel file if you wish.
正如其他人提到的,使用CSV文件是最简单的方法,因为它们可以从 Excel 导入/导出。这可能是最有效的解决方案,因为它只需要标准 C++ 库,并且可能比使用 Excel 库快得多。获得 CSV 文件后,您可以在 Excel 中打开它,并根据需要将其转换为“真正的”Excel 文件。
If you are dealing with .xlsx
files, you can take advantage of the fact that these files are simply zippedcollections of XMLfiles. More information can be found at this website. You would just have to find a zipping library and an XML library.
如果您正在处理.xlsx
文件,您可以利用这些文件只是XML文件的压缩集合这一事实。更多信息可以在这个网站上找到。您只需要找到一个压缩库和一个 XML 库。
Otherwise, there are a few Excel libraries available, such as LibXLor xlsLib.
否则,还有一些 Excel 库可用,例如LibXL或xlsLib。
Finally, there are several posts on StackOverflowabout this very topic. See the following:
最后,StackOverflow上有几篇关于这个主题的帖子。请参阅以下内容:
C++ library to load Excel (.xls) files
What is a simple and reliable C library for working with Excel files?
回答by hansmaad
The easiest way is to export data from Excel as CSV and write back to CSV.
最简单的方法是将数据从 Excel 导出为 CSV 并写回 CSV。
回答by Bill
Check out these pages on OfficeAutomation.
在Office Automation上查看这些页面。
回答by Martin
For native .xls file OLE XLS from SM Software does a decent job... nothing for free though!
对于本机 .xls 文件,来自 SM Software 的 OLE XLS 做得不错……不过没有什么是免费的!