vbscript Union de Excels

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vbscript Union de Excels相关的知识,希望对你有一定的参考价值。

Dim nombreExcelTPV As String = "export tpv.xls"
        Dim nombreExcelCajero As String = "export cajero.xls"
        Dim carpetaUnir As String = "Excels para unir"
        Dim CarpetaOdin As String = "Excel exportado desde odin"
        Dim carpetaExcel As String = ConfigurationManager.AppSettings("carpetaExcel").ToString()
        Dim diUnir As New DirectoryInfo(carpetaExcel + "\" + carpetaUnir + "\")
        Dim fiArr As FileInfo() = diUnir.GetFiles()
        If fiArr.Length > 2 Then
            MsgBox("Hay más de 2 ficheros en '" + carpetaUnir + "'.")
            Exit Sub
        ElseIf fiArr.Length = 1 Then
            MsgBox("Hay menos de 2 ficheros en '" + carpetaUnir + "'.")
            Exit Sub
        ElseIf fiArr.Length = 0 Then
            MsgBox("No hay ficheros en '" + carpetaUnir + "'.")
            Exit Sub
        End If
        'creamos excel export
        Dim xlApp As Excel.Application
        Dim xlWorkBook As Excel.Workbook
        Dim xlWorkSheet As Excel.Worksheet
        Dim misValue As Object = System.Reflection.Missing.Value

        xlApp = New Excel.Application
        xlWorkBook = xlApp.Workbooks.Add(misValue)
        xlWorkSheet = xlWorkBook.Sheets(1)
        
        'leemos excel TPV
        Dim AplicacionTPV As Excel.Application
        Dim LibroTPV As Excel.Workbook
        Dim HojaTPV As Excel.Worksheet

        AplicacionTPV = New Excel.Application
        LibroTPV = AplicacionTPV.Workbooks.Open(carpetaExcel + "\" + carpetaUnir + "\" + nombreExcelTPV)
        HojaTPV = LibroTPV.Worksheets(1)

        Dim FinalRowTPV As Integer
        FinalRowTPV = HojaTPV.Range("A1").End(Excel.XlDirection.xlDown).Row
        'copia excel TPV en excel export
        For i = 1 To FinalRowTPV
            For j = 1 To 7
                xlWorkSheet.Cells(i, j) = HojaTPV.Cells(i, j)
            Next
        Next

        'leemos excel Cajeros
        Dim AplicacionCajeros As Excel.Application
        Dim LibroCajeros As Excel.Workbook
        Dim HojaCajeros As Excel.Worksheet

        AplicacionCajeros = New Excel.Application
        LibroCajeros = AplicacionCajeros.Workbooks.Open(carpetaExcel + "\" + carpetaUnir + "\" + nombreExcelCajero)
        HojaCajeros = LibroCajeros.Worksheets(1)

        Dim FinalRowCajero As Integer
        FinalRowCajero = HojaCajeros.Range("A1").End(Excel.XlDirection.xlDown).Row

        Dim FinalRowExport As Integer
        FinalRowExport = xlWorkSheet.Range("A1").End(Excel.XlDirection.xlDown).Row
        'copia excel cajero en excel export
        For i = 2 To FinalRowCajero
            For j = 1 To 7
                xlWorkSheet.Cells(i + FinalRowExport - 1, j) = HojaCajeros.Cells(i, j)
            Next
        Next

        xlWorkSheet.SaveAs(carpetaExcel + "\" + CarpetaOdin + "\" + "export.xls", Excel.XlFileFormat.xlExcel8) 'excel con formato 97-2003

        xlWorkBook.Close()
        xlApp.Quit()

        releaseObject(xlApp)
        releaseObject(xlWorkBook)
        releaseObject(xlWorkSheet)

        LibroTPV.Close()
        AplicacionTPV.Quit()

        releaseObject(AplicacionTPV)
        releaseObject(LibroTPV)
        releaseObject(HojaTPV)

        LibroCajeros.Close()
        AplicacionCajeros.Quit()

        releaseObject(AplicacionCajeros)
        releaseObject(LibroCajeros)
        releaseObject(HojaCajeros)

以上是关于vbscript Union de Excels的主要内容,如果未能解决你的问题,请参考以下文章

vbscript Manejo de grid SAP

vbscript 文件-AddWatermarkToImagesPowerPointSlide.vb

vbscript 文件-AddWatermarkToImagesPowerPointSlide.vb

vbscript Recorrer DataGridView y cambiar color de fondo de una celda

vbscript Recorrer DataGridView y cambiar color de fondo de una celda

vbscript Comparar campos de dos documentos de Gestar con el mismo form logicamente