| 4013 | } |
| 4014 | |
| 4015 | void SpreadsheetView::exportToFile(const QString& path, const bool exportHeader, const QString& separator, QLocale::Language language) const { |
| 4016 | QFile file(path); |
| 4017 | if (!file.open(QFile::WriteOnly | QFile::Truncate)) { |
| 4018 | RESET_CURSOR; |
| 4019 | QMessageBox::critical(nullptr, i18n("Failed to export"), i18n("Failed to write to '%1'. Please check the path.", path)); |
| 4020 | return; |
| 4021 | } |
| 4022 | |
| 4023 | PERFTRACE(QStringLiteral("export spreadsheet to file")); |
| 4024 | QTextStream out(&file); |
| 4025 | |
| 4026 | int maxRow = maxRowToExport(); |
| 4027 | if (maxRow < 0) |
| 4028 | return; |
| 4029 | |
| 4030 | const int cols = m_spreadsheet->columnCount(); |
| 4031 | QString sep = separator; |
| 4032 | sep = sep.replace(QLatin1String("TAB"), QLatin1String("\t"), Qt::CaseInsensitive); |
| 4033 | sep = sep.replace(QLatin1String("SPACE"), QLatin1String(" "), Qt::CaseInsensitive); |
| 4034 | |
| 4035 | // export header (column names) |
| 4036 | if (exportHeader) { |
| 4037 | for (int j = 0; j < cols; ++j) { |
| 4038 | out << '"' << m_spreadsheet->column(j)->name() << '"'; |
| 4039 | if (j != cols - 1) |
| 4040 | out << sep; |
| 4041 | } |
| 4042 | out << '\n'; |
| 4043 | } |
| 4044 | |
| 4045 | // export values |
| 4046 | QLocale locale(language); |
| 4047 | for (int i = 0; i <= maxRow; ++i) { |
| 4048 | for (int j = 0; j < cols; ++j) { |
| 4049 | Column* col = m_spreadsheet->column(j); |
| 4050 | if (col->columnMode() == AbstractColumn::ColumnMode::Double) { |
| 4051 | const Double2StringFilter* out_fltr = static_cast<Double2StringFilter*>(col->outputFilter()); |
| 4052 | out << locale.toString(col->valueAt(i), out_fltr->numericFormat(), 16); // export with max. precision |
| 4053 | } else |
| 4054 | out << col->asStringColumn()->textAt(i); |
| 4055 | |
| 4056 | if (j != cols - 1) |
| 4057 | out << sep; |
| 4058 | } |
| 4059 | out << '\n'; |
| 4060 | } |
| 4061 | } |
| 4062 | |
| 4063 | void SpreadsheetView::exportToLaTeX(const QString& path, |
| 4064 | const bool exportHeaders, |
nothing calls this directly
no test coverage detected