乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > <em>VS</em>2010用C++怎么读取<em>excel</em>

<em>VS</em>2010用C++怎么读取<em>excel</em>

作者:乔山办公网日期:

返回目录:excel表格制作


excel的版本是2007
用C++标准输出流输到excel中,如果没有回车,数据都在一个单元格中。希望能解决跳到同一行中的下一个单元格中。

你好,


你指的是excel 2013中的表格吗?如果是单纯的表格的话,你可以将excel文件另存为".csv" (comma-sperated-version, 中文为逗号分隔)格式,每个逗号对应的就是表格的一个单元。例如

// Example.csv
Name, Age, ID
David, 23, 0

就是一个2乘2的表格用.csv的形式来表示的,用C++读入这样的csv文件就可以了,代码如下:

void readCSV(const char* fileName, vector<vector<string>>& csvVector)
{
ifstream file(fileName);

while (file)
{
e799bee5baa6e79fa5e98193e58685e5aeb9335string s;
if (!getline(file, s)) break;

istringstream ss(s);
vector <string> record;

while (ss)
{
string s;
if (!getline(ss, s, ',')) break;
record.push_back(s);
}

csvVector.push_back(record);
}
if (!file.eof())
{
cerr << "Fooey!\n";
}
}

参数中的csvVector是一个二维的vector, 分别代表行和列,每次按行读入。


谢谢,希望能帮到你!望采纳!



是你的记事本不够高级 o(╯□╰)o



你好,

你指的是excel 2013中的表格吗?如果是单纯的表格的话e68a84e799bee5baa6e997aee7ad94334,你可以将excel文件另存为".csv" (comma-sperated-version, 中文为逗号分隔)格式,每个逗号对应的就是表格的一个单元。例如

1
2
3

// Example.csv
Name, Age, ID
David, 23, 0

就是一个2乘2的表格用.csv的形式来表示的,用C++读入这样的csv文件就可以了,代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

void readCSV(const char* fileName, vector<vector<string>>& csvVector)
{
ifstream file(fileName);

while (file)
{
string s;
if (!getline(file, s)) break;

istringstream ss(s);
vector <string> record;

while (ss)
{
string s;
if (!getline(ss, s, ',')) break;
record.push_back(s);
}

csvVector.push_back(record);
}
if (!file.eof())
{
cerr << "Fooey!\n";
}
}

参数中的csvVector是一个二维的vector, 分别代表行和列,每次按行读入。

相关阅读

  • <em>VS</em>2010用C++怎么读取<em>excel</em>

  • 乔山办公网excel表格制作
  • excel的版本是2007用C++标准输出流输到excel中,如果没有回车,数据都在一个单元格中。希望能解决跳到同一行中的下一个单元格中。excel中读取内容" src="/uploads/tu/546.jpg" style="width: 400px;
关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网