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

Can't read a file in Windows, Qt creator #7

Open
Yousdel opened this issue Aug 19, 2020 · 2 comments
Open

Can't read a file in Windows, Qt creator #7

Yousdel opened this issue Aug 19, 2020 · 2 comments
Labels
help wanted 도움 필요 Extra attention is needed question 질문 Further information is requested

Comments

@Yousdel
Copy link

Yousdel commented Aug 19, 2020

Hi.
I have that xlnt can't read the excel file 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
#include
#include
#include
#include
#include
#include

#include
#include

#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
four try: xlnt::exception File not found F:/new folder/example.xlsx

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

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

j2doll commented Aug 23, 2020

I don't know if this link will help.
If you found this link helpful, please leave a post.

tfussell/xlnt#145 (comment)

@Yousdel
Copy link
Author

Yousdel commented Sep 7, 2020

xlnt::workbook xlsx(ruta); //with this I think it can read the file
The simple examples of Qxlnt in internet teach it.
I found that method load it's not for my purpose. But I need to make some probes to reach my objective.

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

2 participants