Open a temporary excel in python

0

I have been looking for how to open an excel but I have only found how to open an excel already created:

os.system('start excel.exe "%s\file.xls"' % (sys.path[0], ))

What I'm doing is a "Do you want to open or save the excel?" window, but for the open option, since the excel has not been created and I do not want it to be saved in any I do not know how to tell him.

I was thinking about saving the file and then deleting it but I'm sure that in python there is an option for this.

What I have so far is:

class modalExportacion(QWidget):
    ruta = ""
    fichero_actual = ""

    def __init__(self, df): 
        QWidget.__init__(self)

        self.df = df
        self.setWindowTitle("Exportacion a excel")

        contenedor = QGridLayout()
        self.setLayout(contenedor)

        label_3 = QLabel()
        label_3.setObjectName("label_3")
        label_3.setText("Desea abrir o guardar el excel?")
        contenedor.addWidget(label_3, 1, 1)

        btnAbrir = QPushButton("Abrir",None)
        contenedor.addWidget(btnAbrir,2, 0)
        btnAbrir.clicked.connect(self.abrir)

        btnGuardar = QPushButton("Guardar",None)
        contenedor.addWidget(btnGuardar, 2, 1)
        btnGuardar.clicked.connect(self.guardar)

        btnSalir = QPushButton("Salir",None)
        contenedor.addWidget(btnSalir, 2, 2)
        btnSalir.clicked.connect(self.salir)


    def abrir(self):
        nombre_fichero = QFileDialog.getOpenFileName(self, "Abrir fichero", self.ruta)
        if nombre_fichero:
            self.fichero_actual = nombre_fichero
            self.setWindowTitle(QFileInfo(nombre_fichero).fileName())
            self.ruta = QFileInfo(nombre_fichero).path()

            # TODO - Aqui va el codigo

    def guardar(self):
        options = QFileDialog.Options()
    #     options |= QFileDialog.DontUseNativeDialog
        fileName, _ = QFileDialog.getSaveFileName(self,"Guardar como...","","Excel (*.xls);;Todos los tipos (*)", options=options)
        if fileName:
            #escribimos los datos con pandas
            self.df.to_excel(fileName, index=False)

    def salir(self):
        exit()
    
asked by Adriana_0_0 23.08.2018 в 14:41
source

0 answers