64,282
社区成员
发帖
与我相关
我的任务
分享
#pragma once
#include <iostream>
using std::string;
class SaveData2Excel
{
public:
SaveData2Excel();
string name;
int go(double shuzu[],int length,const wchar_t * excelname);
};
#include "SaveData2Excel.h"
#include "libxl.h"
using namespace std;
using namespace libxl;
SaveData2Excel::SaveData2Excel()
{
}
//将double数组存在创建的Excel文件中,参数为(double数组,double数组长度,Excel文件名)
int SaveData2Excel::go(double tempshuzu[],int tempshuzusize,const wchar_t* &excelname)
{
Book* book = xlCreateXMLBook();
const wchar_t * x = L"Halil Kural";
const wchar_t * y = L"windows-2723210a07c4e90162b26966a8jcdboe";
book->setKey(x, y);
wchar_t * sheetname=L"Sheet1";
Sheet *sheet;
int currentrow;
//首先判断是否存在一个名为excelname的Excel文件,存在,则打开这个Excel文件
if (book->load(excelname))
{
sheet=book->getSheet(0);
currentrow=sheet->lastRow();
}
//若不存在,则根据excelname创建一个新的Excel文件
else
{
sheet = book->addSheet(sheetname);
currentrow=0;
}
int length=tempshuzusize;
for (int i=0;i<length;i++)
sheet->writeNum(currentrow,i,tempshuzu[i]);
book->save(excelname);
book->release();
return 1;
}
#include "libxl.h"
#include "SaveData2Excel.h"
#include "StringTool.h"
#include <fstream>
#include <iostream>
#include <string>
using namespace libxl;
using namespace std;
void main()
{
SaveData2Excel sde;
double shuzu[]={1,2,3,4,5};
for (int i=0;i<10;i++)
{
sde.go(shuzu,5,L"test1.xlsx");
}
}