I'm us'ng Qxlsx for export data to excell. Day, month and year data are not coming as a whole, but separately. I can print them one by one while printing them in excel. How can I combine these 3 data and print it?
here is my code for export
for (i = 0; i < maxRowCount; i) // get maximum data row
{
//strList.clear();
for (j = 0; j < 7; j)
{
/*
j[0] = Temp Değeri
j[1] = Humadity
j[2] = Day
j[3] = moon
j[4] = Year
j[5] = Second
j[6] = Minute
j[7] = Hour
*/
if (i < dataColums[j].count()) {
format.setNumberFormatIndex(2); // for save as number format
if (j == 0)
{
xlsx.write(k, 3, dataColums[j][i], format);
}
else if(j==1)
{
xlsx.write(k, 4, dataColums[j][i], format);
}
else if(j==2 )
{
//here I need write day moon and year when j=2 But I cannot write 3 data on same time.
}
}
k = k 1;
}
CodePudding user response:
Sounds like you just want QString::arg
:
xlsx.write(k, 5, QString("%1/%2/%3").arg(dataColums[4][i]).arg(dataColums[3][i]).arg(dataColums[2][i]));
As an aside, you can make your code a lot cleaner if you eliminate the for-switch pattern:
format.setNumberFormatIndex(2);
for (int j = 0; j < 8; j ) {
maxRowCount = min(maxRowCount, dataColums[j].count());
}
for (i = 0; i < maxRowCount; i , k ) {
xlsx.write(k, 3, dataColums[0][i], format);
xlsx.write(k, 4, dataColums[1][i], format);
xlsx.write(k, 5, QString("%1/%2/%3").arg(dataColums[4][i]).arg(dataColums[3][i]).arg(dataColums[2][i]));
}