PDA

View Full Version : Data exporting to Excel error



rex
20th February 2011, 08:15
Hello friends i have a small problem. I have some data which i store into a sqlite data base.. Which i export to a excel file. Now i am able to export the selected channels but the excel file does't get updated.. Only the column names and one row of temperature data is updated after that the data is not updated into the excel file. It shows empty with only one row of data.. This is my code



if(newfiles==0)
{
newfilename = "E:/"+ QDateTime::currentDateTime().toString("ddd dd-MM-yyyy, hh.mm") +".xls";
newfiles++;
}
file4 = new QFile(newfilename);
file4->open(QFile::ReadWrite | QFile::Text);

QSqlQuery sq1("SELECT "+ colames +" FROM thdata where rowid = " + QString::number(rowcnt1));
while(sq1.next())
{
for (int i = 0; i < colames.size(); i++)
{
tpdata.push_back(sq1.value(i).toString());

}
}
QTextStream out4(file4);

for(int d = 0;d < tempchnames.count();d++) //Selected Channel Names
{
out4 << tempchnames.at(d);
out4 <<'\t'<<'\t' ;
}
out4 << "Time";
out4 <<'\t'<<'\t' ;

out4 <<"\n" <<"";
for(int j=0; j< tpdata.count(); j++) // Selected Channel Data
{
out4 << tpdata.at(j);
out4 <<'\t'<<'\t' ;
}

}
QTextStream out1(file4);
while(!out1.atEnd())
{
QStringList list2;
QString line2 = out1.readLine();
list2 = line2.split("\n");
}
}

dont know what i am doing wrong the data is not been updated after the first row. ??

thank you

rex
20th February 2011, 11:52
Hey i solved my problem.. :) in case some body new with excel file export from sqlite db, i can give u working code of what i wrote..

regards

mpele
21st April 2011, 12:06
Rex,
I am very interested in working with excel files, so could you send to me some "working code".

Thanks,

mcosta
21st April 2011, 17:38
Hi,

Excel, like OpenOffice Calc, reads and automatically converts CSV (Comma Separated Values) files.
The file that REX produced is a special kind of CSV file (with '\t' as separator).

So, if you need to work on "real" Excel files, you have to use other tools.