Unsolved Creating 'xls' file
-
I want to create xls file. I am using this code:-
Void MainWindow::test(){QFile file("hello.xls");
if (file.open(QFile::WriteOnly|QFile::Truncate))
{
QTextStream stream(&file);
stream << "ID" << "\t" << "Date<< "\t" <<"SOFTWARE-Version"<< "\t"<<"UserName";
file.close();
}
}So it is creating file hello.xls but if I open this file then Excel is giving this error:
Excel has detected that 'hello.xls' is a SYLK file, but cannot load it. Either the file has error or it is not a SYLK file format. .....
What is correct way to make excel file with ',xls' format?
Thanks for help
-
-
Hi
XLS is a binary format and its complex to generate.this
stream << "ID" << "\t" << "Date<< "\t" <<"SOFTWARE-Version"<< "\t"<<"UserName";makes a CSV file
excel like tabs so it should just work.You cannot just change the file name to .XLS that can never work.
-
Do you want to create only xls file, not xlsx?
If you interesting to create xlsx files , just use very nice library QtXlsxWriter.
https://github.com/dbzhang800/QtXlsxWriter