1
0
mirror of https://github.com/QtExcel/QXlsx.git synced 2025-01-30 05:02:52 +08:00

testing unsolved issue

This commit is contained in:
Jay Two 2018-12-20 15:30:29 +09:00
parent b7730adb6b
commit d8ab23cc15
17 changed files with 607 additions and 25 deletions

41
IssueTest/IssueTest.pro Normal file
View File

@ -0,0 +1,41 @@
#
# IssueTest.pro
#
# QXlsx # MIT License # https://github.com/j2doll/QXlsx
TARGET = IssueTest
TEMPLATE = app
QT += core
QT += gui
CONFIG += console
CONFIG -= app_bundle
# NOTE: You can fix value of QXlsx path of source code.
# QXLSX_PARENTPATH=./
# QXLSX_HEADERPATH=./header/
# QXLSX_SOURCEPATH=./source/
include(../QXlsx/QXlsx.pri)
##########################################################################
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
##########################################################################
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain
# version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000
# disables all the APIs deprecated before Qt 6.0.0
##########################################################################
# source code
SOURCES += \
main.cpp \
test.cpp

34
IssueTest/main.cpp Normal file
View File

@ -0,0 +1,34 @@
// main.cpp
// QXlsx // MIT License // https://github.com/j2doll/QXlsx
#include <QtGlobal>
#include <QCoreApplication>
#include <QtCore>
#include <QVector>
#include <QVariant>
#include <QDebug>
#include <iostream>
using namespace std;
#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
using namespace QXlsx;
extern int test(QVector<QVariant> params);
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QVector<QVariant> testParams;
int ret = test(testParams);
qDebug() << "test return value : " << ret;
return 0;
}

33
IssueTest/test.cpp Normal file
View File

@ -0,0 +1,33 @@
// test.cpp
// QXlsx // MIT License // https://github.com/j2doll/QXlsx
#include <QtGlobal>
#include <QCoreApplication>
#include <QtCore>
#include <QVector>
#include <QVariant>
#include <QDebug>
#include <iostream>
using namespace std;
#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
using namespace QXlsx;
int test(QVector<QVariant> params)
{
return 0;
}

View File

@ -32,12 +32,14 @@ class QIODevice;
class QByteArray;
QT_BEGIN_NAMESPACE_XLSX
class Relationships;
class AbstractOOXmlFilePrivate;
class AbstractOOXmlFile
{
Q_DECLARE_PRIVATE(AbstractOOXmlFile)
public:
enum CreateFlag
{
@ -45,6 +47,7 @@ public:
F_LoadFromExists
};
public:
virtual ~AbstractOOXmlFile();
virtual void saveToXmlFile(QIODevice *device) const = 0;

View File

@ -41,7 +41,7 @@ class ChartPrivate;
class CellRange;
class DrawingAnchor;
class Chart : public AbstractOOXmlFile
class Chart : public AbstractOOXmlFile
{
Q_DECLARE_PRIVATE(Chart)

View File

@ -1,25 +1,17 @@
//--------------------------------------------------------------------
//
// QXlsx
// MIT License
// https://github.com/j2doll/QXlsx
//
// QtXlsx
// https://github.com/dbzhang800/QtXlsxWriter
// http://qtxlsx.debao.me/
// MIT License
// xlsxglobal.h
// QXlsx // MIT License // https://github.com/j2doll/QXlsx
// QtXlsx // MIT License // https://github.com/dbzhang800/QtXlsxWriter // http://qtxlsx.debao.me/
#ifndef XLSXGLOBAL_H
#define XLSXGLOBAL_H
#include <QtGlobal>
#include <QObject>
#define QT_BEGIN_NAMESPACE_XLSX namespace QXlsx {
#define QT_END_NAMESPACE_XLSX }
#define QXLSX_USE_NAMESPACE using namespace QXlsx;
#endif // XLSXGLOBAL_H

View File

@ -1,15 +1,6 @@
// QXlsx
// MIT License
// https://github.com/j2doll/QXlsx
//
// QtXlsx
// https://github.com/dbzhang800/QtXlsxWriter
// http://qtxlsx.debao.me/
// MIT License
//
// main.cpp
//
// QXlsx // MIT License // https://github.com/j2doll/QXlsx
// QtXlsx // MIT License // https://github.com/dbzhang800/QtXlsxWriter // http://qtxlsx.debao.me/
#include <QCoreApplication>
#include <QtCore>

Binary file not shown.

6
chartsquestions/LICENSE Normal file
View File

@ -0,0 +1,6 @@
chartsquestions
sat_gui
Copyright (c) 2018 edosad(github) All rights reserved.

14
chartsquestions/main.cpp Normal file
View File

@ -0,0 +1,14 @@
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Q_INIT_RESOURCE(test);
MainWindow w;
w.show();
return a.exec();
}

View File

@ -0,0 +1,46 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QObject::connect(ui->pushButton, SIGNAL(clicked()),this,SLOT(generator()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::generator()
{
sat_calc calc;
calc.generate_report();
/*
int check=0;
if(ui->lineEdit_chrom->text()!="*.txt"&&!ui->lineEdit_chrom->text().isEmpty()){
calc.get_chromatogram(ui->lineEdit_chrom->text());
check+=1;
}
if(!ui->lineEdit_report->text().isEmpty()){
check+=1;
calc.get_report_file(ui->lineEdit_report->text());
}
if(!ui->lineEdit_sheet->text().isEmpty()){
check+=1;
calc.get_sheet_name(ui->lineEdit_sheet->text());
}
if(!ui->lineEdit_prec->text().isEmpty()){
check+=1;
calc.get_precision(ui->lineEdit_prec->text().toDouble());
}
if(4==check)
calc.generate_report();
*/
}

View File

@ -0,0 +1,26 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "sat_calc.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void generator();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

View File

@ -0,0 +1,154 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>386</width>
<height>306</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>371</width>
<height>261</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Chromatogram</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit_chrom">
<property name="enabled">
<bool>false</bool>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>*.txt</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Report file</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEdit_report">
<property name="enabled">
<bool>false</bool>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>*.xlsx</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Sheet_name</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="lineEdit_sheet">
<property name="enabled">
<bool>false</bool>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_18">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>precision</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="lineEdit_prec">
<property name="enabled">
<bool>false</bool>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>0.1</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QPushButton" name="pushButton">
<property name="font">
<font>
<pointsize>15</pointsize>
</font>
</property>
<property name="text">
<string>Generate</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,158 @@
#include <QtGlobal>
#include <QObject>
#include <QUrl>
#include <QFile>
#include <QString>
#include <QMessageBox>
#include "sat_calc.h"
sat_calc::sat_calc(): output_line_count(5){}
sat_calc::~sat_calc(){}
void sat_calc::get_chromatogram(const QString & chromatogram){
this->chromatogram=chromatogram;
}
void sat_calc::get_report_file(const QString & report_file){
this->report_file=report_file;
}
void sat_calc::get_sheet_name(const QString & sheet_name){
this->sheet_name=sheet_name;
}
void sat_calc::get_precision(const double precision){
this->precision=precision;
}
#define QUICK_GUI_DEBUG USE
// fixed for testing by j2doll
void sat_calc::generate_report()
{
// Define test parameters
chromatogram = ":/Chromatogram_example.txt";
report_file = "output.xlsx";
sheet_name = "hello";
precision = 0.1;
double d1, d2, d3;
bool isExist = QFile::exists(chromatogram);
if (!isExist)
{
qDebug() << "[debug] file is not exist. : " << chromatogram;
#ifdef QUICK_GUI_DEBUG
QMessageBox msgBox;
msgBox.setText("File is not exist.");
msgBox.exec();
#endif
return;
}
QFile input( chromatogram );
if ( !input.open( QIODevice::ReadOnly | QIODevice::Text ) )
{
qDebug() << "[debug] failed to load file : " << chromatogram ;
#ifdef QUICK_GUI_DEBUG
QMessageBox msgBox;
msgBox.setText("Failed to load file.");
msgBox.exec();
#endif
return;
}
QXlsx::Document output(report_file);
output.addSheet(sheet_name);
output.selectSheet(sheet_name);
QString chrom_data_array = "A" + QString::number(output_line_count + 3);
unsigned int input_line_count=0;
int step = 1;
QString string_buffer, trash;
QTextStream stream_buffer(&input);
QXlsx::Format row_data, simple_green, title_stile;
row_data.setBorderStyle(QXlsx::Format::BorderThin);
row_data.setHorizontalAlignment(QXlsx::Format::AlignHCenter);
row_data.setNumberFormat("0.000");
simple_green.setFontColor(QColor(Qt::green));
simple_green.setBorderStyle(QXlsx::Format::BorderThin);
title_stile.setFontBold(true);
title_stile.setHorizontalAlignment(QXlsx::Format::AlignHCenter);
title_stile.setVerticalAlignment(QXlsx::Format::AlignVCenter);
title_stile.setPatternBackgroundColor(QColor(225,225,225));
title_stile.setBorderStyle(QXlsx::Format::BorderMedium);
output.write( output_line_count+2, 1, "volume, ml", title_stile );
output.write( output_line_count+2, 2, "OD, mAu", title_stile );
while ( !stream_buffer.atEnd() )
{
if ( input_line_count % step == 0 )
{
for ( int j = 0 ; j < 2 ; j++ )
{
if ( input_line_count > 2 )
{
if ( input_line_count == 2 && j == 0 )
{
stream_buffer >> string_buffer;
}
if ( input_line_count == 3 && j == 0 )
{
stream_buffer >> d1;
output.write( output_line_count, j+1, d1, simple_green );
}
if ( input_line_count == 4 && j == 0 )
{
stream_buffer >> d2;
step = (int)(precision / (d2-d1));
std::cout << "\nstep " << step << std::endl;
output.write( output_line_count, j+1, d2, simple_green );
}
if ( j || input_line_count > 4 )
{
stream_buffer >> d3;
output.write( output_line_count, j+1, d3, row_data );
}
} // if ( input_line_count > 2 ) ...
} // for (int j = 0 ; j < 2 ; j++ )
output_line_count++;
} // if ( input_line_count % step == 0 )
trash = stream_buffer.readLine();
input_line_count++;
}
chrom_data_array += ":B" + QString::number(output_line_count - 1);
Chart * Crom = output.insertChart( 3, 5, QSize(600, 500) );
Crom->setChartType( Chart::CT_Scatter );
Crom->addSeries( CellRange(chrom_data_array) );
qDebug() << "[debug] chrom_data_array : " << chrom_data_array;
output.saveAs(report_file);
input.close();
QMessageBox msgBox;
msgBox.setText("Success to write a xlsx file.");
msgBox.exec();
}

View File

@ -0,0 +1,36 @@
#ifndef SAT_CALC_H
#define SAT_CALC_H
#include <QtCore>
#include <QString>
#include <QTextStream>
#include <iostream>
#include <QColor>
#include "xlsxdocument.h"
#include "xlsxformat.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
using namespace QXlsx;
class sat_calc
{
private:
QString chromatogram;
double precision;
QString report_file;
QString sheet_name;
int output_line_count;
public:
void generate_report (void);
void get_chromatogram(const QString & chromatogram);
void get_report_file (const QString & report_file) ;
void get_sheet_name (const QString & sheet_name) ;
void get_precision (const double precision) ;
sat_calc();
~sat_calc();
};
#endif // SAT_CALC_H

View File

@ -0,0 +1,43 @@
#
# sat_gui.pro
#
# Copyright (c) 2018 edosad(github) All rights reserved.
# Some code is fixed by j2doll.
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = sat_gui
TEMPLATE = app
# NOTE: You can fix value of QXlsx path of source code.
# QXLSX_PARENTPATH=./
# QXLSX_HEADERPATH=./header/
# QXLSX_SOURCEPATH=./source/
include(../QXlsx/QXlsx.pri)
# include("D:\resin_example\sat_gui\src\xlsx\qtxlsx.pri")
# QMAKE_LFLAGS += -static -static-libgcc
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
main.cpp \
mainwindow.cpp \
sat_calc.cpp
HEADERS += \
mainwindow.h \
sat_calc.h
FORMS += \
mainwindow.ui
RESOURCES += \
test.qrc
#OTHER_FILES += \
#Chromatogram_example.txt

5
chartsquestions/test.qrc Normal file
View File

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/">
<file>Chromatogram_example.txt</file>
</qresource>
</RCC>