| 83 | } |
| 84 | |
| 85 | void MainWindow::openExcelFile() |
| 86 | { |
| 87 | // Show warning / information message before opening the file dialog |
| 88 | QMessageBox::StandardButton choice = QMessageBox::question( |
| 89 | this, |
| 90 | "Information", |
| 91 | "If the xlsx file is large, opening it may take a significant amount of time.\n\n" |
| 92 | "Do you want to continue and select a file?", |
| 93 | QMessageBox::Yes | QMessageBox::No, |
| 94 | QMessageBox::Yes |
| 95 | ); |
| 96 | |
| 97 | if (choice != QMessageBox::Yes) |
| 98 | return; |
| 99 | |
| 100 | QString filePath = QFileDialog::getOpenFileName( |
| 101 | this, |
| 102 | "Select Excel File", |
| 103 | QString(), |
| 104 | "Excel File (*.xlsx)" |
| 105 | ); |
| 106 | |
| 107 | if (filePath.isEmpty()) |
| 108 | return; |
| 109 | |
| 110 | // First, read sheet names using QXlsx::Document |
| 111 | Document doc(filePath); |
| 112 | if (!doc.isLoadPackage()) |
| 113 | { |
| 114 | QMessageBox::warning( |
| 115 | this, |
| 116 | "Error", |
| 117 | "Failed to load the Excel file." |
| 118 | ); |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | const QStringList sheetNames = doc.sheetNames(); |
| 123 | if (sheetNames.isEmpty()) |
| 124 | { |
| 125 | QMessageBox::information( |
| 126 | this, |
| 127 | "Info", |
| 128 | "The Excel file has no sheets." |
| 129 | ); |
| 130 | return; |
| 131 | } |
| 132 | |
| 133 | clearTabs(); |
| 134 | |
| 135 | // For each sheet, create a model and a view, and add as a tab |
| 136 | for (const QString &sheetName : sheetNames) |
| 137 | { |
| 138 | ExcelModel *model = new ExcelModel(this); |
| 139 | if (!model->loadFromXlsx(filePath, sheetName)) |
| 140 | { |
| 141 | delete model; |
| 142 | continue; |
nothing calls this directly
no test coverage detected