- LibXL for Windows 3.5.3 : http://www.libxl.com/download/libxl.zip
Using library
- 解壓縮後整包放到C槽
建立在Microsoft Visual C++環境下
- add include directory in your project, for example: c:\libxl\include_cpp
Project -> Properties -> C/C++ -> General -> Additional Include Directories
- add library directory in your project, for example: c:\libxl\lib
- add libxl.lib in project dependencies:
- copy bin\libxl.dll to directory of your project
使用前先引入標頭檔與命名空間
- #include "libxl.h"
- using namespace libxl;
建立一個excel物件叫book
- Book* book = xlCreateBook();
如果建立book成功的話,在book內新建一個分頁物件叫sheet
- if(book)
- Sheet* sheet = book->addSheet(L"Sheet1");
- if(sheet)
- sheet->writeStr(2, 1, L"Hello, World !"); //寫在excel的3,b
- sheet->writeNum(3, 1, 1000); //寫在excel的4,b
- col and row參數都比實際excel位置 都會少1
寫完了要存檔成叫做example.xls的excel檔案
- book->save(L"example.xls");
- book->release();
讀取一個excel檔(如果讀取成功)
- if(book->load(L"example.xls"))
- Sheet* sheet = book->getSheet(0);
- const wchar_t* s = sheet->readStr(2, 1);
- double d = sheet->readNum(3, 1);
網站:http://www.libxl.com/home.html



沒有留言:
張貼留言