① 绘制Excel
1. 大二下学期的时候,由于算法的运行时间要用Excel画折线图,不想一个一个复制就找怎样直接把时间绘制在Excel表格里面的某些位置的方法。
2. 当时找到的方法是用.csv后缀名的文件进行输入输出流,然后用逗号隔开即可。方便了算法时间记录的工作。
第一个文件 Excel.h
#ifndef EXCEL_H
#define EXCEL_H
class Excel{
private:
double D[90000];
public:
Excel();
bool put(double a,int r,int c);
void display();
void CreateExcel();
};
#endif
第二个文件 Excel.cpp
#include<iostream>
#include "Excel.h"
#include<string>
#include<fstream>
using namespace std;
Excel::Excel(){
memset(D,0,sizeof(D));
}
bool Excel::put(double a,int r,int c){
if(D[r*300+c]==0){
D[r*300+c]=a;
return true;
}
else{
return false;
}
}
void Excel::display(){
int i=-1,j;
for(;++i<300;){
for(j=-1;++j<299;){
cout<<D[i*300+j]<<',';
}
cout<<D[i*300+j]<<endl;
}
}
void Excel::CreateExcel(){
ofstream fout;
int i=-1,j;
fout.open("I:\\1.csv");
for(;++i<300;){
for(j=-1;++j<299;){
if(D[i*300+j]){
fout<<D[i*300+j];
}
else{
fout<<" ";
}
fout<<',';
}
if(D[i*300+j]){
fout<<D[i*300+j]<<endl;
}
else{
fout<<" "<<endl;
}
}
fout.close();
}
调用put函数来将double值放在表格第几行第几列。
放完以后调用CreateExcel();来创建csv文件。
② 绘制Word文档
最近研究的,需要用到MFC。
===================================================================