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 Long10 11 Dim BOX As String12 13 Application.ScreenUpdating = False14 15 MyPath = ActiveWorkbook.Path16 17 MyName = Dir(MyPath & "\" & "*.xls")18 19 AWbName = ActiveWorkbook.Name20 21 Num = 022 23 Do While MyName <> ""24 25 If MyName <> AWbName Then26 27 Set Wb = Workbooks.Open(MyPath & "\" & MyName)28 29 Num = Num + 130 31 With Workbooks(1).ActiveSheet32 33 .Cells(.Range("B65536").End(xlUp).Row + 2, 1) = Left(MyName, Len(MyName) - 4)34 35 For G = 1 To Sheets.Count36 37 Wb.Sheets(G).UsedRange.Copy .Cells(.Range("B65536").End(xlUp).Row + 1, 1)38 39 Next40 41 WbN = WbN & Chr(13) & Wb.Name42 43 Wb.Close False44 45 End With46 47 End If48 49 MyName = Dir50 51 Loop52 53 Range("B1").Select54 55 Application.ScreenUpdating = True56 57 MsgBox "共合并了" & Num & "个工作薄下的全部工作表。如下:" & Chr(13) & WbN, vbInformation, "提示"58 59 End Sub
4.运行之后,等待10秒针左右,等运行完毕,就是合并完成之后,会有提示,点确定就可以了
参考链接: