在C ++中从Excel读取单元格吗?
我想知道如何使用C ++从Excel电子表格中读取特定的单元格.我知道我们必须使用"fstream"库,但是我不知道我该如何从某个单元格中获取这些值,并将其打印在屏幕上.任何帮助,将不胜感激,谢谢!Carpetfizz
I was wondering how you can read specific cells from an Excel spreadsheet, in C++. I understand we have to use the "fstream" library, but I don't know exactly how I could get those values from a certain cell, and print it on the screen. Any help would be appreciated, thanks! Carpetfizz
在Linux中,您可以免费使用: http://libxls.sourceforge.net/
in linux you have this free: http://libxls.sourceforge.net/
在Windows中,您有 http://www.libxl.com/似乎很花钱:
in windows you have http://www.libxl.com/ which seems to cost money:
Book* book = xlCreateBook();
if(book)
{
if(book->load(L"example.xls"))
{
Sheet* sheet = book->getSheet(0);
if(sheet)
{
const wchar_t* s = sheet->readStr(2, 1);
if(s) wcout << s << endl;
double d = sheet->readNum(3, 1);
cout << d << endl;
}
}
我认为最好的方法是将文件另存为 .csv
,这样操作起来更加友好.
I think the best thing to do is to save the files as .csv
which is more friendly to work with.
更多参考文献: