Modificar contenido de un archivo Excel

66 views
Skip to first unread message

Carlos Morales

unread,
Feb 8, 2018, 1:53:28 PM2/8/18
to WINDEV-LA
Buen dia, Alguien sabe si se puede modificar los datos que contenga un archivo excel desde Webdev? ya que quiero manejar una plantilla y editar la informacion de las celdas.

nexus133

unread,
Feb 8, 2018, 6:36:35 PM2/8/18
to WINDEV-LA
Buen dia

Hice algo parecido en windev para esto me base en una clase  demo que existe en el tutorial de WINDEV y que se puede agregar al proyecto.

En resumido, se debe instanciar el objeto applicacion de excel dentro de la clase. una vez instanciado se puede utilizar las funciones.

el contenido de la clase es: (copiado de la clase de ejemplo que trae windev)

Cexcel is Class
    m_pautExcel is object OLE dynamic    // Pointer to active object
    m_nVersion is int          // Version of Excel installed on the computer
    m_sCurrentFolder is string    // name of the current workbook
END

PROCEDURE Constructor(bRecycle=False)
// if bRecycle=True, use Excel that is already opened

// check whether Excel is installed and retrieve its version
nVersion is int
nVersion = :nVersionOffice(“Excel”)
IF nVersion = 0 THEN
    EndProgram("")
    RETURN
END
IF nVersion < 8 THEN
    EndProgram("")
    RETURN   
END

// version of Excel
:m_nVersion = nVersion

// if Excel is not already allocated
IF :m_pautExcel = Null THEN
    // if the user wants to use Excel that is already opened
    IF bRecycle THEN
        :m_pautExcel = GetActiveObject(“Excel.Application”) //inicializacion del objeto excel.
        IF :m_pautExcel = Null THEN
            // no Excel is already opened, allocate one
            :m_pautExcel = new object OLE “Excel.Application”
        END
    ELSE
        // allocate a new one
        :m_pautExcel = new object OLE “Excel.Application”
    END
END

// Make visible
:m_pautExcel>>visible=True

PROCEDURE Destructor()
IF :m_pautExcel<>Null THEN
    :exit()
    Multitask(-10)
   
    // free the pointer
    delete :m_pautExcel
END

ahora en el evento init del formulario donde selecciono los datos tengo esto:

// variable para automatizacion OLE de excel
gpclExcel is object dynamic Cexcel // hace referencia a la clase citada anteriormente
// arreglo de nombres de hojas de la plantilla de excel
nombrehoja is array of strings = ["Recibido", "Enviado", "Rechazado"]

en el boton que llenara la plantilla tengo esto:

// instancia la clase EXCEL
ToastDisplay("Abriendo excel",toastLong,vaMiddle,haCenter)
gpclExcel = new Cexcel(True)
gpclExcel:OpenworkBook(nombrearchivo)
gpclExcel.m_pautExcel>>DisplayAlerts = False
ToastDeleteAll()

// escribe en la hoja 1 ("RECIBIDO")
gpclExcel.m_pautExcel>>sheets(nombrehoja[1])>>Select //nombrehoja es el array definido anteriormente
gpclExcel.m_pautExcel>>ActiveSheet
gpclExcel.m_pautExcel>>Cells(2,1) = sRuc
gpclExcel.m_pautExcel>>Cells(2,2) = sRazonsocial
gpclExcel.m_pautExcel>>Cells(2,3) = anioinfo
gpclExcel.m_pautExcel>>Cells(2,4) = NumToString(COMBO_meses,"02d")
gpclExcel.m_pautExcel>>Cells(2,5)>>numberformat = "@"
gpclExcel.m_pautExcel>>Cells(2,5) = "001"
gpclExcel.m_pautExcel>>Cells(2,6)>>Numberformat = "#########0.00"
gpclExcel.m_pautExcel>>Cells(2,6) = rTotalventa-rTotalcreditos

Se escribira la informacion desde la celda 2 columnas 1...... todo dentro de un for..end para mi caso.

Espero no haber confundido
Reply all
Reply to author
Forward
0 new messages