Python的numpy处理起来会比较方便,有空实现一下,这里是Excel内部代码的方式:
合并方法如下:
1.需要把多个excel表都放在同一个文件夹里面,并在这个文件夹里面新建一个excel。如图所示:
2.用microsoft excel打开新建的excel表,并右键单击sheet1,找到“查看代码”,单击进去。进去之后就看到了宏计算界面。如图所示:
3.然后把下面这些宏计算的代码复制进去,然后找到工具栏上面的“运行”下的“运行子过程/用户窗体”,代码如下,如图所示:
1 Sub 合并当前目录下所有工作簿的全部工作表() 2 3 Dim MyPath, MyName, AWbName 4 5 Dim Wb As Workbook, WbN As String 6 7 Dim G As Long 8 9 Dim Num As Long 10 11 Dim BOX As String 12 13 Application.ScreenUpdating = False 14 15 MyPath = ActiveWorkbook.Path 16 17 MyName = Dir(MyPath & "\" & "*.xls") 18 19 AWbName = ActiveWorkbook.Name 20 21 Num = 0 22 23 Do While MyName <> "" 24 25 If MyName <> AWbName Then 26 27 Set Wb = Workbooks.Open(MyPath & "\" & MyName) 28 29 Num = Num + 1 30 31 With Workbooks(1).ActiveSheet 32 33 .Cells(.Range("B65536").End(xlUp).Row + 2, 1) = Left(MyName, Len(MyName) - 4) 34 35 For G = 1 To Sheets.Count 36 37 Wb.Sheets(G).UsedRange.Copy .Cells(.Range("B65536").End(xlUp).Row + 1, 1) 38 39 Next 40 41 WbN = WbN & Chr(13) & Wb.Name 42 43 Wb.Close False 44 45 End With 46 47 End If 48 49 MyName = Dir 50 51 Loop 52 53 Range("B1").Select 54 55 Application.ScreenUpdating = True 56 57 MsgBox "共合并了" & Num & "个工作薄下的全部工作表。如下:" & Chr(13) & WbN, vbInformation, "提示" 58 59 End Sub
4.运行之后,等待10秒针左右,等运行完毕,就是合并完成之后,会有提示,点确定就可以了
参考链接:多个EXCEL文件合并成一个