PDA

View Full Version : Creating new sheets in csv file



anh5kor
11th December 2015, 10:54
I am trying to write a data in csv file as below



QStringList l;
QFile file("Book.csv");
QTextStream out(&file);
l<<"StatusFrame1"<<"PORstat"<<"name";
if(file.open(QIODevice::WriteOnly))
{

out<<l.at(0).toStdString().c_str()<<","<<l.at(1).toStdString().c_str()<<"\n";
out<<l.at(0).toStdString().c_str()<<","<<l.at(1).toStdString().c_str()<<"\n";
}


file.close();

The above code create a csv file(with one sheet) and successfully write the data on that sheet
But I want one more new sheet to be created or added in same csv file(like how we have number of sheets in one excel file)
So please let me know how can I create two or more sheets in one csv file.

d_stranz
11th December 2015, 17:26
A CSV file is a flat ASCII file. There is no concept of "sheets" in such a file. You are obviously confused because Excel can export a single page of a workbook to a CSV format file, but once it is in that format there is no connection between that and a "Sheet" as defined by Excel. It's an ASCII file, and that's all it is.

anda_skoa
12th December 2015, 09:15
A CSV file is a flat ASCII file. There is no concept of "sheets" in such a file.

Exactly.

However, if Excel can interpret some form of markup in such files to import different sections into different sheets, then this might still work.
But then this would have to be asked for on an Excel forum, since it is Excel specific.

Though it could be easily tested by having Excel export to CSV and import into a new document. If the sheets are still separated, then the file should contain the necessary markup, if they are not, then Excel can't do that.

Cheers,
_

d_stranz
13th December 2015, 01:04
I have not seen any way in Excel to export more than a single sheet to any ASCII format, and indeed, the CSV files created contain only the printable contents of the cells in the exported sheet, nothing more (like meta-information on the workbook, sheets, etc.)