Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading file issue #6

Open
Raul-Cardona opened this issue May 8, 2020 · 3 comments
Open

Reading file issue #6

Raul-Cardona opened this issue May 8, 2020 · 3 comments
Labels
help wanted 도움 필요 Extra attention is needed question 질문 Further information is requested

Comments

@Raul-Cardona
Copy link

Hi,
I am trying to execute the code for the simple example that you posted for reading from an existing file but I get an error on Mac. Do you know why this is?

@Raul-Cardona
Copy link
Author

Screen Shot 2020-05-08 at 3 53 02 PM

@j2doll
Copy link
Member

j2doll commented May 9, 2020

Dear @Raul-Cardona

1️⃣ A file is required for accurate analysis. exampless.xlsx
I don't know if it's a bug in xlnt.

2️⃣ I don't have a Mac, so I only work on Windows and Linux.
(Without support, I have no money to buy a MacBook. 😭 )

@j2doll j2doll added help wanted 도움 필요 Extra attention is needed question 질문 Further information is requested labels May 9, 2020
@Yousdel
Copy link

Yousdel commented Aug 18, 2020

Hi.
I have a similar problem in Windows 10, 64 bits, I'm using Qt creator, but I'm relatively new to modern code.
Some code:

#include "widget.h"
#include "ui_widget.h"
#include "persona_reducida.h"
#include "personadialog.h"
#include "listadobusq_o_err_dialog.h"
#include "filtro.h"

#include <operaciones_con_qstrings.h>

#include <QFileDialog>
#include <QFile>
#include <QMessageBox>
#include <QInputDialog>
#include <QSystemTrayIcon>
#include <QAction>
#include <QTableWidgetItem>

#include <QtGlobal>
#include <QVariant>

#include <xlnt/xlnt.hpp>
using namespace std;
...
void Widget::on_abrir_clicked()
{
    QFileDialog fd;//--------------------------------caja de dialogo para que tome el excel
    fd.setDefaultSuffix(".xlsx");
    fd.setDirectory(QDir::homePath());
   nombre_de_file = fd.getOpenFileName();
//    nombre_de_file = nombre_de_file.split("/").join("\\");  //   first try
//    nombre_de_file.insert(nombre_de_file.indexOf("\\"), "\\");
        nombre_de_file.insert(nombre_de_file.indexOf("/"), "/"); //   second try
if (nombre_de_file.isEmpty() || nombre_de_file.isNull())
   {
       nombre_de_file= filename_anterior;
       ui->espere_cartel->hide(); ui->progressBar->hide();
       return;
   }
QFileInfo archinfo;
   archinfo.setFile(nombre_de_file);
    if (archinfo.suffix().contains("xls") == false){
        QMessageBox::critical(this, "Error: no es un archivo Excel",
                                        "El archivo seleccionado no es un archivo Excel como se espera. Seleccione correctamente el archivo.");
        nombre_de_file = "";
        ui->espere_cartel->hide();
        ui->progressBar->hide();return; //salir
    }
xlnt::path ruta(nombre_de_file.toStdString());
    xlnt::workbook xlsx;  //solo para leer la informacion
    try{
        xlsx.load(ruta);      // Here *********************************** an exception
    }catch(...)
    {
        mSystemTrayIcon->showMessage("Nuevo Mensaje",
                                     "Hay un mensaje de error para usted en el Control de Embarazadas.");
        QString s1 = e.what();
        QMessageBox::critical(nullptr,
                              "Error de archivo",
                              "Exception: "+
                              s1 +
                              ". Error al abrir el archivo. Esto puede deberse a que otro programa tiene abierto el archivo, o se ha generado una excepción. Si es así, trate de cerrar el archivo en el otro programa primero.");
        nombre_de_file = "";
        ui->abrir->setEnabled(0);
        ui->espere_cartel->hide();
        ui->progressBar->hide();return; //salir
    }
...

It generate an exception in the load line:
in my first try xlnt::exception File not found F:\new folder\example.xlsx
second try: xlnt::exception File not found F://new folder/example.xlsx
third try: xlnt::exception File not found F:/new folder/example.xlsx

I'll thanks a lot if somebody can help me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted 도움 필요 Extra attention is needed question 질문 Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants