Dim d As Date = Args(0) Dim f1 As String = args(1) Dim file As String = args(2) If file.EndsWith(".xls") OrElse file.EndsWith(".xlsx") Then Dim Book1 As New XLS.Book(file) Dim str As String For Each Sheet As XLS.Sheet In Book1.Sheets str = str + Sheet.name + "," Next Dim Sheet2 As XLS.Sheet = Book1.Sheets("资产负债表") Dim s As String = Sheet2(3,0).Value s = s.SubString(s.Length - 6) s = s.Substring(0,2) s = s & Format(d,"yyyyMM") & ".xls" Dim App As New MSExcel.Application Dim wb As MSExcel.WorkBook = App.WorkBooks.open(ProjectPath & f1) Dim ws1 As MSExcel.WorkSheet = wb.WorkSheets("分户快报") Dim ws2 As MSExcel.WorkSheet = wb.WorkSheets("资产负债表") Dim ws3 As MSExcel.WorkSheet = wb.WorkSheets("利润及分配表") Dim ws4 As MSExcel.WorkSheet = wb.WorkSheets("费用表") Dim ws5 As MSExcel.WorkSheet = wb.WorkSheets("工资月报") Dim ws6 As MSExcel.WorkSheet = wb.WorkSheets("附列资料") ws2.cells(4,1).Value = Sheet2(3,0).Value '单位名称 ws2.cells(2,1).Value = Sheet2(1,0).Value '日期 If str.Contains("分户快报") Then Dim Sheet1 As XLS.Sheet = Book1.Sheets("分户快报") For n1 As Integer = 3 To 5 For n2 As Integer = 4 To 48 If ws1.cells(n2+1,n1+1).Formula = "" Then ws1.cells(n2+1,n1+1).Value = val(Sheet1(n2,n1).Value) End If Next Next Else app.DisplayAlerts = False ws1.delete End If If str.Contains("资产负债表") Then For n1 As Integer = 2 To 3 For n2 As Integer = 5 To 54 If ws2.cells(n2+1,n1+1).Formula = "" Then ws2.cells(n2+1,n1+1).Value = val(Sheet2(n2,n1).Value) End If If ws2.cells(n2+1,n1+5).Formula = "" Then ws2.cells(n2+1,n1+5).Value = val(Sheet2(n2,n1+4).Value) End If Next Next Else app.DisplayAlerts = False ws2.delete End If If str.Contains("利润及分配表") Then Dim Sheet3 As XLS.Sheet = Book1.Sheets("利润及分配表") For n1 As Integer = 2 To 3 For n2 As Integer = 6 To 35 If ws3.cells(n2+1,n1+1).Formula = "" Then ws3.cells(n2+1,n1+1).Value = val(Sheet3(n2,n1).Value) End If If ws3.cells(n2+1,n1+5).Formula = "" Then ws3.cells(n2+1,n1+5).Value = val(Sheet3(n2,n1+4).Value) End If Next Next Else app.DisplayAlerts = False ws3.delete End If If str.Contains("费用表") Then Dim Sheet4 As XLS.Sheet = Book1.Sheets("费用表") For n1 As Integer = 3 To 6 For n2 As Integer = 4 To 32 If ws4.cells(n2+1,n1+1).Formula = "" Then ws4.cells(n2+1,n1+1).Value = val(Sheet4(n2,n1).Value) End If Next Next Else app.DisplayAlerts = False ws4.delete End If If str.Contains("工资月报") Then Dim Sheet5 As XLS.Sheet = Book1.Sheets("工资月报") For n1 As Integer = 3 To 4 For n2 As Integer = 4 To 24 If ws5.cells(n2+1,n1+1).Formula = "" Then ws5.cells(n2+1,n1+1).Value = val(Sheet5(n2,n1).Value) End If Next Next Else app.DisplayAlerts = False ws5.delete End If If str.Contains("附列资料") Then Dim Sheet6 As XLS.Sheet = Book1.Sheets("附列资料") For n1 As Integer = 1 To 13 For n2 As Integer = 2 To 19 If ws6.cells(n2+1,n1+1).Formula = "" Then ws6.cells(n2+1,n1+1).Value = val(Sheet6(n2,n1).Value) End If Next Next Else app.DisplayAlerts = False Wb.WorkSheets("附列资料附表").delete ws6.delete End If For Each Ws As MSExcel.WorkSheet In Wb.WorkSheets ws.UsedRange.Formula = ws.UsedRange.Formula ws.Activate app.ActiveWindow.DisplayZeros = False Next FileSys.RenameFile(file, s) wb.save wb.close App.Quit End If
|