原創|使用教程|編輯:何躍|2022-01-06 11:10:16.467|閱讀 1110 次
概述:這個例子從工作表的所有單元格中讀取數據,檢測單元格的類型并打印其數值。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
LibXL是一個輕量級的Excel類庫,支持各類平臺運行,如需使用先行點擊這里下載:
這個例子從工作表的所有單元格中讀取數據,檢測單元格的類型并打印其數值:
#include <iostream> #include "libxl.h" using namespace libxl; int main() { Book* book = xlCreateBook(); if(book->load(L"input.xls")) { Sheet* sheet = book->getSheet(0); if(sheet) { for(int row = sheet->firstRow(); row < sheet->lastRow(); ++row) { for(int col = sheet->firstCol(); col < sheet->lastCol(); ++col) { CellType cellType = sheet->cellType(row, col); std::wcout << "(" << row << ", " << col << ") = "; if(sheet->isFormula(row, col)) { const wchar_t* s = sheet->readFormula(row, col); std::wcout << (s ? s : L"null") << " [formula]"; } else { switch(cellType) //數據處理 { case CELLTYPE_EMPTY: std::wcout << "[empty]"; break; case CELLTYPE_NUMBER: { double d = sheet->readNum(row, col); std::wcout << d << " [number]"; break; } case CELLTYPE_STRING: { const wchar_t* s = sheet->readStr(row, col); std::wcout << (s ? s : L"null") << " [string]"; break; } case CELLTYPE_BOOLEAN: { bool b = sheet->readBool(row, col); std::wcout << (b ? "true" : "false") << " [boolean]"; break; } case CELLTYPE_BLANK: std::wcout << "[blank]"; break; case CELLTYPE_ERROR: std::wcout << "[error]"; break; } } std::wcout << std::endl; } } } } // 為了應用的性能,記得釋放資源呀 book->release(); return 0; }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn