libxl库 学习,读写excel中数据
2016-02-25 14:00
399 查看
程序如下:
配置:
1、把include_cpp 和libxl.lib,libxl.dll文件放到工程中。并在属性---VC++目录,包含这个目录
2、依赖项中加入Libxl.lib库
3、包含#include "include_cpp/libxl.h"
using namespace libxl;
以下程序是把一个excel表格中的数据写入到 MNIST手写体识别 文件中,
写入4个字节的数据,读4个字节的数据,去掉了文件头
#include "stdafx.h"
#include <iostream>
#include <iostream>
#include <fstream>
#include <opencv2/opencv.hpp>
#include "include_cpp/libxl.h"
using namespace libxl;
using namespace std;
using namespace cv;
/*
#define NUMBER_OF_TRAINING_SAMPLES 60000
#define ATTRIBUTES_PER_SAMPLE 784
#define NUMBER_OF_TESTING_SAMPLES 10000
#define NUMBER_OF_CLASSES 10
*/
#define NUMBER_OF_TRAINING_SAMPLES 5120 //训练样本个数
#define ATTRIBUTES_PER_SAMPLE 21 //有多少列
#define NUMBER_OF_TESTING_SAMPLES 825 //测试样本个数
#define NUMBER_OF_CLASSES 4 //种类个数
int _tmain(int argc, _TCHAR* argv[])
{
ofstream outfile1,outfile2;
outfile1.open("train-images.idx3-ubyte",ios::binary);
outfile2.open("train-labels.idx1-ubyte",ios::binary);
//表示需要读出测试样例
ofstream testfile1,testfile2;
testfile1.open("t10k-images.idx3-ubyte",ios::binary);
testfile2.open("t10k-labels.idx1-ubyte",ios::binary);
Book *book = xlCreateBook(); // xlCreateXMLBook() for xlsx
CellType ct;
bool f=book->load("testnewdata.xls");
Sheet *sheet =book->getSheet(0);
int cellnum;
int label;
//写训练数据与label
for (int i=0;i<NUMBER_OF_TRAINING_SAMPLES;i++)
{
for (int j=1;j<ATTRIBUTES_PER_SAMPLE+1;j++)
{
//ct = sheet->cellType(i,j);//单元格的数据类型 1表示是数字 2表示是字符串
cellnum = (int)sheet->readNum(i,j);
outfile1.write((char *)&cellnum ,4);
//s = sheet->readStr(i,j);
//outfile1.write(s ,1);
}
label = sheet->readNum(i,0);
outfile2.write((char *)&label,4);
}
//写测试数据与label
for (int i=0;i<NUMBER_OF_TESTING_SAMPLES;i++)
{
for (int j=1;j<ATTRIBUTES_PER_SAMPLE+1;j++)
{
//ct = sheet->cellType(i,j);//单元格的数据类型 1表示是数字 2表示是字符串
cellnum = sheet->readNum(i,j);
testfile1.write((char *)&cellnum ,4);
}
label = sheet->readNum(i,0);
testfile2.write((char *)&label,4);
}
outfile1.close();
outfile2.close();
testfile1.close();
testfile2.close();
return 0;
}
#include "stdafx.h" #include <iostream> #include "include_cpp/libxl.h" using namespace libxl; using namespace std; int _tmain(int argc, _TCHAR* argv[]) { Book* book = xlCreateBook(); // xlCreateXMLBook() for xlsx if(book) { Sheet* sheet = book->addSheet(L"Sheet1"); if(sheet) { sheet->writeStr(2, 1, L"Hello, World !"); sheet->writeNum(3, 1, 1000); } book->save(L"example.xls"); book->release(); } return 0; }
配置:
1、把include_cpp 和libxl.lib,libxl.dll文件放到工程中。并在属性---VC++目录,包含这个目录
2、依赖项中加入Libxl.lib库
3、包含#include "include_cpp/libxl.h"
using namespace libxl;
以下程序是把一个excel表格中的数据写入到 MNIST手写体识别 文件中,
写入4个字节的数据,读4个字节的数据,去掉了文件头
#include "stdafx.h"
#include <iostream>
#include <iostream>
#include <fstream>
#include <opencv2/opencv.hpp>
#include "include_cpp/libxl.h"
using namespace libxl;
using namespace std;
using namespace cv;
/*
#define NUMBER_OF_TRAINING_SAMPLES 60000
#define ATTRIBUTES_PER_SAMPLE 784
#define NUMBER_OF_TESTING_SAMPLES 10000
#define NUMBER_OF_CLASSES 10
*/
#define NUMBER_OF_TRAINING_SAMPLES 5120 //训练样本个数
#define ATTRIBUTES_PER_SAMPLE 21 //有多少列
#define NUMBER_OF_TESTING_SAMPLES 825 //测试样本个数
#define NUMBER_OF_CLASSES 4 //种类个数
int _tmain(int argc, _TCHAR* argv[])
{
ofstream outfile1,outfile2;
outfile1.open("train-images.idx3-ubyte",ios::binary);
outfile2.open("train-labels.idx1-ubyte",ios::binary);
//表示需要读出测试样例
ofstream testfile1,testfile2;
testfile1.open("t10k-images.idx3-ubyte",ios::binary);
testfile2.open("t10k-labels.idx1-ubyte",ios::binary);
Book *book = xlCreateBook(); // xlCreateXMLBook() for xlsx
CellType ct;
bool f=book->load("testnewdata.xls");
Sheet *sheet =book->getSheet(0);
int cellnum;
int label;
//写训练数据与label
for (int i=0;i<NUMBER_OF_TRAINING_SAMPLES;i++)
{
for (int j=1;j<ATTRIBUTES_PER_SAMPLE+1;j++)
{
//ct = sheet->cellType(i,j);//单元格的数据类型 1表示是数字 2表示是字符串
cellnum = (int)sheet->readNum(i,j);
outfile1.write((char *)&cellnum ,4);
//s = sheet->readStr(i,j);
//outfile1.write(s ,1);
}
label = sheet->readNum(i,0);
outfile2.write((char *)&label,4);
}
//写测试数据与label
for (int i=0;i<NUMBER_OF_TESTING_SAMPLES;i++)
{
for (int j=1;j<ATTRIBUTES_PER_SAMPLE+1;j++)
{
//ct = sheet->cellType(i,j);//单元格的数据类型 1表示是数字 2表示是字符串
cellnum = sheet->readNum(i,j);
testfile1.write((char *)&cellnum ,4);
}
label = sheet->readNum(i,0);
testfile2.write((char *)&label,4);
}
outfile1.close();
outfile2.close();
testfile1.close();
testfile2.close();
return 0;
}
相关文章推荐
- 哈理工OJ 2271 从前的苹果树(简单的规律题)
- ELF entry point和装载地址
- SVN使用svnadmin dump进行备份时报“拒绝访问”错误
- mysql连接
- javascript的变量声明提升
- 简单工厂模式(simple factory pattern)
- nginx+iis实现负载均衡
- scrapy 让指定的spider执行指定的pipeline
- bootstrap 响应式工具
- 面向对象程序设计__Task3_Calculator
- github配置密钥
- Raspberry Pi INSTALLING OPERATING SYSTEM IMAGES ON MAC OS
- centos7 adb问题解决办法
- 月薪2W和1W的工作,你会怎么选
- Android MediaRecorder 录音
- 图文详解YUV420数据格式
- HDU1008—Elevator
- 20145120黄玄曦 《java程序设计》 寒假学习总结
- HTML5基础知识习题 一
- 一条汇编指令引发的 蝴蝶效应 (后记)