Writing QString to Excel produce extra Tab?

106 views Asked by At

After working with my initial Data.CSV, I want to save it again as Data.CSV, while that works already amazingly well, it somehow writes in the wrong Column when I open it in Excel.

Somehow wrongly written Data:

Somehow wrongly written Data

That is how I write it to the File:

QFile file(fileName);
QString DataFullConvert;
DataFullConvert = DataFullConvert.trimmed();
qDebug() << DataFullConvert;
if (!file.open(QFile::WriteOnly | QFile::Text)){
    qDebug() << file.errorString();
}
else{
    QTextStream stream(&file);
    stream << DataFullConvert;

That's how my qDebug() looks like: qDebug Output:
qDebug Output

I noticed always that qt is doing a newline before the Strings I changed (the 8-digit Numbers).

I tried already using trimmed();, but the Outcome was the same. Any Ideas what it could be?

1

There are 1 answers

2
Minh On BEST ANSWER

You should get rid of the semi-colons after the newline characters. When Excel sees the newline character, it assumes a new row starts, and then it sees the semi-colon, which creates the first empty column.

DataFullConvert.replace(QString("\n;"), QString("\n"));