I have a some class which allows to write in a *.xls (not a *.xlsx) files.
//XLSWriter.cpp
//---------------------------------------------------------------------------
#include "stdafx.h"
#include "XLSWriter.h"
#include <string.h>
XLSWriter::XLSWriter(int MaxRow)
: out(NULL) ,blank(BLANK) ,bof(BOF_BIFF5) ,iMaxRow(MaxRow) ,tmp(BLANK)
{
iWordSize = sizeof(unsigned short);
cell_attr[0] = 0xFF; // default cell attributes
cell_attr[1] = 0xFF;
cell_attr[2] = 0x00;
}
XLSWriter::~XLSWriter()
{
if(out)
fclose(out);
}
void XLSWriter::Blank()
{
fwrite(&blank,iWordSize,1,out);
}
void XLSWriter::BOF()
{
fwrite(&bof,iWordSize,1,out);
tmp = 0x0006;
fwrite(&tmp,iWordSize,1,out);
Blank();
}
//---------------------------------------------------------------------------
void XLSWriter::DocTypeXls()
{
tmp = DOCTYPE_XLS;
fwrite(&tmp,iWordSize,1,out);
Blank();
Blank();
}
void XLSWriter::DIM()
{
tmp = DIM_LEN;
fwrite(&tmp,iWordSize,1,out);
Blank();
tmp = (unsigned short) iMaxRow;
fwrite(&tmp,iWordSize,1,out);
Blank();
tmp=10;
fwrite(&tmp,iWordSize,1,out);
}
void XLSWriter::WriteEOF()
{
tmp = BIFF_EOF;
fwrite(&tmp,iWordSize,1,out);
Blank();
}
void XLSWriter::WriteCellAttr()
{
fwrite(&cell_attr,sizeof(cell_attr),1,out);
}
void XLSWriter::WriteLabel()
{
tmp = LABEL;
fwrite(&tmp,iWordSize,1,out);
}
bool XLSWriter::CreateXls(const char* FileName)
{
if(!FileName || FileName[0] == 0)
return false;
if(out)
CloseXls();
out = fopen(FileName,"wb");
if(!out)
return false;
BOF();
DocTypeXls();
DIM();
return true;
}
void XLSWriter::CloseXls()
{
WriteEOF();
fclose(out);
tmp = BLANK;
}
void XLSWriter::WriteData(const char* Data,int row, int col)
{
WriteLabel();
int len = strlen(Data);
tmp = (unsigned short) 8 + len;
fwrite(&tmp,iWordSize,1,out);
tmp = (unsigned short) row;
fwrite(&tmp,iWordSize,1,out);
tmp = (unsigned short)col;
fwrite(&tmp,iWordSize,1,out);
WriteCellAttr();
unsigned char btmp = (unsigned char) len;
fwrite(&btmp,1,1,out);
fwrite(Data,btmp,1,out);
}
I am not the author of this class. This class from a free library. I've found it in the google.