• 将两个excel文件合并到一个新的Excel文件中


    1、首先需要安装autoit,这个网上应该有很多

    2、创建两个文件,里边写一些东西

    3、脚本编写

    #cs ----------------------------------------------------------------------------
    
     AutoIt Version: 3.3.14.5
     Author:         myName
    
     Script Function:
        Template AutoIt script.
    
    #ce ----------------------------------------------------------------------------
    
    ; Script Start - Add your code below here
    #include <Excel.au3>
    #include <MsgBoxConstants.au3>
    #include-once
    #include "Array.au3"
    #include "ExcelConstants.au3"
    
    Local $oExcel = _Excel_Open()
    Local $filePath = $CmdLine[1]
    Local $oWorkBook = _Excel_BookOpen($oExcel,$filePath)
    
    Local $targetPath = $CmdLine[2]
    Local $oWorkBook1 = _Excel_BookOpen($oExcel,$targetPath)
    
    
    Local $oWorkBook2 = _Excel_BookNew($oExcel,Default)
    
    
    Local $oSheetList = _Excel_SheetList($oWorkBook)
    
    Dim $i
    
    For $i=1 To UBound($oSheetList)
       Local $oSheet = _Excel_SheetCopyMove($oWorkbook,$i,$oWorkBook2,$i,False,Default)
       $oSheet.Name = "a" & $i
    Next
    
    Local $oSheetList1 = _Excel_SheetList($oWorkBook1)
    
    ;_Excel_BookSaveAs($oWorkBook2,"d:/merge.xls")
    
    Dim $j
    For $j=1 To UBound($oSheetList1)
       $toIndex = UBound($oSheetList) + $j
       Local $oSheet1 = _Excel_SheetCopyMove($oWorkbook1,$j,$oWorkBook2,$toIndex,False,Default)
       $oSheet1.Name = "a" & $toIndex
    Next
    
    _Excel_BookSaveAs($oWorkBook2,"d:/merge.xls")
    
    _Excel_SheetDelete($oWorkBook2,1);
    
    _Excel_Close($oExcel)
    
    MsgBox(64,"提示","执行完成")

    4、按照本机的位数,编译成相关的exe文件

    5、最后进入到cmd,执行xxx.exe d:/source.xls d:/target.xls

    合并后的文件路径脚本里有写

     合并后的文件

    补充:

    将多个Excel文件合并到一个文件中

    #cs ----------------------------------------------------------------------------
    
     AutoIt Version: 3.3.14.5
     Author:         myName
    
     Script Function:
        Template AutoIt script.
    
    #ce ----------------------------------------------------------------------------
    
    ; Script Start - Add your code below here
    #include <Excel.au3>
    #include-once
    #include "Array.au3"
    #include "ExcelConstants.au3"
    
    Local $source = $CmdLine[1]
    
    Local $sourceArray = StringSplit($source,",")
    
    Local $target = $CmdLine[2]
    
    Local $oExcel = _Excel_Open()
    
    Local $tWorkBook = _Excel_BookNew($oExcel,Default)
    
    Dim $sum = 0
    
    For $i = 1 To $sourceArray[0]
         Local $item = $sourceArray[$i]
         Local $itemWorkBook = _Excel_BookOpen($oExcel,$item)
         Local $itemSheetList = _Excel_SheetList($itemWorkBook)
         For $j = 1 To UBound($itemSheetList)
             $toIndex = $sum + 1
             Local $itemSheet = _Excel_SheetCopyMove($itemWorkBook,$j,$tWorkBook,$toIndex,False,Default)
             $itemSheet.Name = "a" & $toIndex
             $sum = $sum + 1
          Next
    Next
    
    
    _Excel_BookSaveAs($tWorkBook,$target)
    
    _Excel_SheetDelete($tWorkBook,1)
    
    _Excel_Close($oExcel)

     执行方式

    大致流程:就是将第一个参数切割成数组,然后循环添加到新创建的Excel文件中

  • 相关阅读:
    Class constructor FileManager cannot be invoked without 'new' in undefined (line undefined, column undefined)
    vscode插件
    面试题
    使用NPOI读取word表格里面的图片
    Postgresql安装过程记录
    .net Core 新增Area的步骤
    kendo grid上的模版示例
    unicode与string之间的转换
    使用yarn安装puppeteer失败的解决方案
    abp第一篇《框架的下载与mysql数据库的切换》
  • 原文地址:https://www.cnblogs.com/nihaofenghao/p/12131554.html
Copyright © 2020-2023  润新知