File indexing completed on 2024-12-22 03:35:50

0001 /*
0002     File                 : XLSXFilter.h
0003     Project              : LabPlot
0004     Description          : XLSX I/O-filter
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2021 Fabian Kristof (fkristofszabolcs@gmail.com)
0007     SPDX-FileCopyrightText: 2022-2023 Stefan Gerlach <stefan.gerlach@uni.kn>
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #ifndef XLSXFILTER_H
0012 #define XLSXFILTER_H
0013 #include "backend/datasources/filters/AbstractFileFilter.h"
0014 
0015 #include <QObject>
0016 
0017 #include <memory>
0018 
0019 #ifdef HAVE_QXLSX
0020 #include "xlsxcellrange.h"
0021 #include "xlsxcellreference.h"
0022 #include "xlsxdocument.h"
0023 #endif
0024 
0025 class XLSXFilterPrivate;
0026 class QTreeWidgetItem;
0027 
0028 class XLSXFilter : public AbstractFileFilter {
0029     Q_OBJECT
0030 public:
0031     explicit XLSXFilter();
0032     virtual ~XLSXFilter() override;
0033     static QString fileInfoString(const QString& fileName);
0034     static QStringList sheets(const QString& fileName, bool* ok = nullptr);
0035     static bool isValidCellReference(const QString& cellRefString);
0036 
0037 #ifdef HAVE_QXLSX
0038     QVector<QStringList> previewForDataRegion(const QString& sheet, const QXlsx::CellRange& region, bool* okToMatrix, int lines);
0039 #endif
0040     QVector<QStringList> previewForCurrentDataRegion(int lines, bool* okToMatrix);
0041     QStringList sheets() const;
0042 
0043     void setExportAsNewSheet(bool);
0044     void setSheetToAppendTo(const QString& sheetName);
0045     void setOverwriteData(bool);
0046     void setDataExportStartPos(const QString&);
0047     void setFirstRowAsColumnNames(bool);
0048     void setColumnNamesAsFirstRow(bool);
0049 
0050     void parse(const QString& fileName, QTreeWidgetItem* root);
0051 
0052 #ifdef HAVE_QXLSX
0053     QVector<QXlsx::CellRange> dataRegions(const QString& fileName, const QString& sheetName);
0054     QXlsx::CellRange dimension() const;
0055 #endif
0056     void setCurrentRange(const QString&);
0057 
0058     void setCurrentSheet(const QString&);
0059     virtual void readDataFromFile(const QString& fileName, AbstractDataSource* = nullptr, ImportMode = ImportMode::Replace) override;
0060     virtual void write(const QString& fileName, AbstractDataSource*) override;
0061 
0062     virtual void save(QXmlStreamWriter*) const override;
0063     virtual bool load(XmlStreamReader*) override;
0064 
0065     void setStartRow(const int);
0066     int startRow() const;
0067     void setEndRow(const int);
0068     int endRow() const;
0069     void setStartColumn(const int);
0070     int startColumn() const;
0071     void setEndColumn(const int);
0072     int endColumn() const;
0073     int firstColumn() const;
0074 
0075 private:
0076     std::unique_ptr<XLSXFilterPrivate> const d;
0077     friend class XLSXFilterPrivate;
0078 };
0079 
0080 #endif // XLSXFILTER_H