/*csv格式是以逗号分隔列的。
* 每行内容是以换行符作为一行的。
* 如果内容中包含换行符,则整个内容要以双引号括起来。
* 如果内容中包含逗号,则整个内容要以双引号括起来。
* 如果内容中又有双引号,则会是2个双引号连在一起表示一个双引号。
* 每个字段的左右2边的空白字符可以忽略。
* 还有其他复杂的情况,暂时不考虑
*/
/*针对以上csv的复杂多变的格式,我们这里只考虑以下几种情况吧:
* 1. 逗号分隔列。
* 2. 某个列的内容可能多行显示。
* 3. 某个列可能存在逗号、双引号、换行。
*/
QList<QStringList> parseCSVFile(const QString &strFile)
{
QList<QStringList> allRecordSets;
QFile file(strFile);
if (!file.open(QFile::ReadOnly)) return allRecordSets;
QTextStream ins(&file);
bool bInQuote = false;
const QChar chQuote('\"');
const QChar chEnter('\n');
const QChar chComma(',');
int iFileLineCount = 0;
QStringList currentRecordset;
QString strFieldData;
while (!ins.atEnd())
{
++iFileLineCount;
const QString strLine = ins.readLine()