| 409 | |
| 410 | #ifdef HAVE_QXLSX |
| 411 | void XLSXFilterPrivate::readDataRegion(const QXlsx::CellRange& region, AbstractDataSource* dataSource, AbstractFileFilter::ImportMode importMode) { |
| 412 | DEBUG(Q_FUNC_INFO << ", col/row range = " << region.firstColumn() << " .. " << region.lastColumn() << ", " << region.firstRow() << " .. " |
| 413 | << region.lastRow() << ". first row as column names = " << firstRowAsColumnNames) |
| 414 | |
| 415 | int columnOffset = 0; |
| 416 | const auto rowCount = currentRange.rowCount(); |
| 417 | const auto colCount = currentRange.columnCount(); |
| 418 | auto regionToRead = region; |
| 419 | bool isDateOnly = true; |
| 420 | |
| 421 | if (auto* spreadsheet = dynamic_cast<Spreadsheet*>(dataSource)) { |
| 422 | std::vector<void*> numericDataPointers; |
| 423 | QVector<QVector<QDateTime>*> datetimeDataPointers; |
| 424 | QVector<QVector<QString>*> stringDataPointers; |
| 425 | QList<QXlsx::Cell::CellType> columnNumericTypes; |
| 426 | QStringList columnNames; |
| 427 | if (firstRowAsColumnNames) |
| 428 | regionToRead.setFirstRow(region.firstRow() + 1); |
| 429 | |
| 430 | // determine column type (numeric or not) |
| 431 | for (int col = regionToRead.firstColumn(); col <= regionToRead.lastColumn(); ++col) { |
| 432 | columnNumericTypes.push_back(columnTypeInRange(col, regionToRead)); |
| 433 | if (firstRowAsColumnNames) |
| 434 | columnNames.push_back(read(regionToRead.firstRow() - 1, col).toString()); |
| 435 | else |
| 436 | columnNames.push_back(AbstractFileFilter::convertFromNumberToColumn(col)); |
| 437 | } |
| 438 | |
| 439 | spreadsheet->setUndoAware(false); |
| 440 | columnOffset = spreadsheet->resize(importMode, columnNames, colCount); |
| 441 | |
| 442 | if (importMode == AbstractFileFilter::ImportMode::Replace) { |
| 443 | spreadsheet->clear(); |
| 444 | spreadsheet->setRowCount(rowCount); |
| 445 | } else { |
| 446 | if (spreadsheet->rowCount() < (rowCount)) |
| 447 | spreadsheet->setRowCount(rowCount); |
| 448 | } |
| 449 | |
| 450 | for (int n = 0; n < colCount; ++n) { |
| 451 | auto* col = spreadsheet->column(columnOffset + n); |
| 452 | if (columnNumericTypes.at(n) == QXlsx::Cell::CellType::NumberType) { |
| 453 | col->setColumnMode(AbstractColumn::ColumnMode::Double); |
| 454 | auto* data = static_cast<QVector<double>*>(col->data()); |
| 455 | numericDataPointers.push_back(data); |
| 456 | if (importMode == AbstractFileFilter::ImportMode::Replace) |
| 457 | data->clear(); |
| 458 | } else if (columnNumericTypes.at(n) == QXlsx::Cell::CellType::DateType) { |
| 459 | col->setColumnMode(AbstractColumn::ColumnMode::DateTime); |
| 460 | auto* data = static_cast<QVector<QDateTime>*>(col->data()); |
| 461 | datetimeDataPointers.push_back(data); |
| 462 | if (importMode == AbstractFileFilter::ImportMode::Replace) |
| 463 | data->clear(); |
| 464 | } else { |
| 465 | col->setColumnMode(AbstractColumn::ColumnMode::Text); |
| 466 | auto* data = static_cast<QVector<QString>*>(col->data()); |
| 467 | stringDataPointers.push_back(data); |
| 468 | if (importMode == AbstractFileFilter::ImportMode::Replace) |
nothing calls this directly
no test coverage detected