前言:
一年前在学数据库的时候,有个想法,就是怎么用代码来读取excel的数据;为此,我曾请教Boss Liu,Boss Liu指点说OpenSource里有我要的东西。由于一些小事情,耽搁了,结果这个想法就over了;没想到,现在我需要用上;既然如此,那我得好好学学。在此我要感谢Boss Liu的指导,否则对于这问题,我估计现在也不知道怎么解决;
正题:
BasicExcel
1.设计者:新加坡人Yap Chun Wei;
2.基本的功能(对excel里的sheet进行的操作):
1)Read and write number (integers, real numbers) and strings (ANSI, UTF16)
2)Add worksheets
3)Rename worksheets
4)Delete worksheets
5)Get the name of a worksheet
3.优点:
1)采用com方式实现,访问速度快,api接口也比较简单
2)可以跨平台使用
4.一些操作(读取操作)的具体实现
1)prepare:
下载BasicExcel;说明:该包里面有四个文件,由于演示程序不是没用MFC,所以只需要将BasicExcel.hpp与BasicExcel.cpp放在你建的工程下面,或者可以将四个文件都放在你自己的类库中,然后导入;
使用的excel的名字:classification.data.xls
sheet的名字:analysis.data
2)show:
#include "BasicExcel.hpp"
// Load a workbook with one sheet, display its contents
int main(int argc, char* argv[])
{
BasicExcel e;
// load excel
e.Load("classification.data.xls");
BasicExcelWorksheet* sheet = e.GetWorksheet("analysis.data");
if (sheet){
size_t maxRows = sheet->GetTotalRows();
size_t maxCols = sheet->GetTotalCols();
cout << "Dimension of " << sheet->GetAnsiSheetName() <<
" (" << maxRows << ", " << maxCols << ")" << endl;
for (size_t r = 0; r < maxRows; ++r){
printf("%10d", r+1);
for (size_t c = 0; c < maxCols; ++c){
BasicExcelCell* cell = sheet->Cell(r,c);
switch (cell->Type())
{
case BasicExcelCell::UNDEFINED:
printf(" ");
break;
case BasicExcelCell::INT:
printf("%10d", cell->GetInteger());
break;
case BasicExcelCell::DOUBLE:
printf("%10.6lf", cell->GetDouble());
break;
case BasicExcelCell::STRING:
printf("%10s", cell->GetString());
break;
case BasicExcelCell::WSTRING:
wprintf(L"%10s", cell->GetWString());
break;
}
}
cout << endl;
}
}else{
printf("cannot read this sheet!\n");
}
cout << endl;
return 0;
}
#include "BasicExcel.hpp"
// Create a new workbook and write some contents.
int main(int argc, char* argv[])
{
BasicExcel e;
// create a workbook
e.New();
// create a sheet
BasicExcelWorksheet* sheet = e.AddWorksheet("analysis.data");
// cell
BasicExcelCell* cell;
if (sheet){
size_t c;
// SetString
for (c = 0; c < 4; ++c){
cell = sheet->Cell(0, c);
cell->SetString("property");
// sheet->Cell(0,c)->SetInteger("property");
}
// SetInteger
for (c = 0; c < 4; ++c){
cell = sheet->Cell(1, c);
cell->SetInteger(c);
// sheet->Cell(1,c)->SetInteger(c);
}
// SetDouble
for (c = 0; c < 4; ++c){
cell = sheet->Cell(2, c);
double data = c / 2.0;
cell->SetDouble(data);
// sheet->Cell(2,c)->SetDouble(data);
}
}
// save to a excel
e.SaveAs("classification.data.xls");
return 0;
}
分享到:
相关推荐
opensource-windows-x86-winrt-msvc2015-5.8.0.exe 20-Jan-2017 12:54 1.2G Details qt-opensource-windows-x86-winrt-msvc2013-5.8.0.exe 20-Jan-2017 12:53 1.2G Details qt-opensource-windows-x86-msvc2015_64...
所以今天收集了qt-opensource-linux-x64-5.10.0.run 、 qt-opensource-linux-x64-5.12.1.run 、qt-opensource-linux-x64-5.12.6.run、qt-opensource-linux-x64-5.12.9.run 、qt-opensource-linux-x64-5.12.12.run给...
JUnit是一个开放原始码的Java测试框架,用来撰写与执行重复性的测试,它是用于单元测试框架的xUnit架构的实例.本文对其使用做了介绍。
qt-everywhere-opensource-src-5.9.8
qt-opensource-windows-x86-5.13.2.exe
qt-opensource-windows-x86-5.14.2
qt-sdk-win-opensource-2010.04
Why do commercial companies contribute to open source software
qt-opensource-linux-x64-5.12.12.run Qt(官方发音 [kju:t],音同 cute)是一个跨平台的 C++ 开发库,主要用来开发图形用户界面(Graphical User Interface,GUI)程序,当然也可以开发不带界面的命令行(Command ...
qt-opensource-linux-x64-5.6.2.run
Qt qt-opensource-windows-x86-5.11.0安装包,适用于开发openCV、QtAndroid
自己用的qt安装包第三部分qt-opensource-windows-x86-5.14.2.part3.rar
Open Source BI Comparison
qt-opensource-linux-x64-5.11.1.run 最新linux 18内核QT开发开源,文件1.2G左右,提供的是百度云盘下载链接。
windows 下载的QT开发包 qt-opensource-windows-x86-msvc2010-5.5.1 qt-vs-addin-1.2.5 非常的好用.VS2008 vs2010都可以用。
qt-opensource-windows-x86-msvc2012-5.6.3 这个是在vs2012中的使用的qt 编绎时使用的命令: configure -prefix d:\win32-msvc2012 -platform win32-msvc2012 -opensource -confirm-license -nomake tests -nomake ...
qtserialport-opensource-src-5.4.2.tar,可以编译到qt4
官网qt-x11-opensource-src-4.2.2.tar.gz下载
qt-opensource-linux-x64-5.9.0.run 已验证可用,请放心下载。Qt是诺基亚公司的C++可视化开发平台。与Visual C++相比,Qt简单方便、功能完善、跨平台、扩展能力强,可以用于嵌入式开发