1.开始时准备在vsat010下通过C++读取Excel,需要 ole等 但方法总是配置不好。
感兴趣的可以参考http://www.cnblogs.com/kernel0815/p/3318182.html
2.最后做项目发现,对于excel文件其实最好的处理方式是:用读取.csv,
因为它们可以互相转化只是在csv文件中每个量直接由逗号隔开,也可以直接读.。
在此代码栗子分享
待处理文件 data.csv如下:
#image/照片ID,time/时间,latitude/纬度,longitude/经度,altitude/高程,roll/滚转觿,pitch/俯仰觿,yaw/航向觿
1,2016/11/30 11:31,34.37583,112.83631,746.12,0.5,0.1,81.3
2,2016/11/30 11:31,34.37582,112.83741,744.66,-0.1,3.1,79.5
3,2016/11/30 11:31,34.37581,112.83848,743.45,0.5,7,80.3
4,2016/11/30 11:31,34.37581,112.83955,744.45,-0.7,6.7,80.8
实现代码
ReadCsv.cpp : 定义控制台应用程序的入口点。
#include "stdafx.h"
#include <opencv\highgui.h>
#include <iostream>
#include <string>
#include <fstream>
#include <opencv2/highgui/highgui.hpp>
#define ExampleNum 114 //.csv文件中样本数据行数
using namespace std;
using namespace cv;
int main()
{
ifstream file("data.csv");
string data[ExampleNum+1][8];
string value;
int row = 0;
while (getline(file,value)) {
//istream& getline (istream&& is, string& str);
//读取的istream是作为参数is传进函数的。读取的字符串保存在string类型的str中。
istringstream sin(value);
//istringstream::istringstream(string str);它的作用是从string对象str中读取字符。
string field;
int col = 0;
while (getline(sin, field, ',')) {
data[row][col] = field;
col = col + 1;
}
cout << data[row][0] << "\t" <&l