I need a feature to save the data of qtableview as local excel sheet,i can get data from qtableview,i can make sure that values have been token correctly from qtableview when i step into my 'SetCellValue' function,but they are incorrect in my excel sheet
Get value from qtableview and set them into my excel sheet
for (int row = 0; row < m_nDefectNum[2]; row++)
{
QModelIndex NoModelIndex = categoriesTableList[2]->model()->index(row, 0);
QModelIndex NameModelIndex = categoriesTableList[2]->model()->index(row, 1);
QModelIndex backACountModelIndex = categoriesTableList[2]->model()->index(row, 2);
QModelIndex backARateModelIndex = categoriesTableList[2]->model()->index(row, 3);
QModelIndex backBCountModelIndex = categoriesTableList[3]->model()->index(row, 2);
QModelIndex backBRateModelIndex = categoriesTableList[3]->model()->index(row, 3);
QString backCountStr = QString::number(categoriesTableList[2]->model()->data(backACountModelIndex).toInt() + categoriesTableList[3]->model()->data(backBCountModelIndex).toInt());
QString backRateStr = QString::number(categoriesTableList[2]->model()->data(backARateModelIndex).toDouble() + categoriesTableList[3]->model()->data(backBRateModelIndex).toDouble(), 'f', 2) + "%";
excel->SetCellValue(row + 1, 0, categoriesTableList[2]->model()->data(NoModelIndex).toString());
excel->SetCellValue(row + 1, 1, categoriesTableList[2]->model()->data(NameModelIndex).toString());
excel->SetCellValue(row + 1, 2, backCountStr);
excel->SetCellValue(row + 1, 3, backRateStr);
}
SetCellValue
void ExcelExporterHelper::SetCellValue(int row, int column, const QString& value)
{
int cellRow = row + 1;
int cellCol = column + 1;
QAxObject* pRange = m_pSheet->querySubObject("Cells(int,int)", cellRow, cellCol);
pRange->dynamicCall("SetValue(const QString&)",value);
}
such as , the value i get are "300 30%",they will become "300 300%" when i see the excel file,i don't know what's wrong with my code, i need some help, i can sure that values have been token from qtableview successfully,but failed when they are saved into excel