1 Sub Print_Click() 2 '打印信息 3 Dim columnCount As Integer '列数 4 Dim rowCount As Integer '行数 5 columnCount = getColumnCount(XsXxSheet) 6 rowCount = Application.CountA(ActiveSheet.Range("B:B")) 7 If rowCount = 0 Then 8 MsgBox ("没有数据,无需打印!") 9 Exit Sub 10 End If 11 If rowCount = 1 Then 12 MsgBox ("没有数据,无需打印!") 13 Exit Sub 14 End If 15 '提示信息 16 Dim mess As String 17 Worksheets("错误信息").Visible = True 18 mess = Sheets("错误信息").Cells(1, 1) 19 notContinueBool = True 20 If mess = "" Then 21 ShowForm.MessageLabel.Caption = "学生信息还未进行校验,是否进行打印?" 22 ShowForm.Show 23 ElseIf InStr(mess, "数据校验成功") > 0 Then 24 notContinueBool = False 25 Else 26 ShowForm.MessageLabel.Caption = "学生基本信息中存在错误,是否继续打印?" 27 ShowForm.Show 28 End If 29 ShowForm.Hide 30 If notContinueBool Then 31 ShowForm.Hide 32 Exit Sub 33 End If 34 35 PrintForm.Show 36 Dim beginInt As Integer 37 Dim endInt As Integer 38 If PrintForm.AllOptionButton = Flase And PrintForm.NumOptionButton = Flase Then 39 Exit Sub 40 End If 41 If PrintForm.AllOptionButton Then 42 beginInt = 2 43 endInt = rowCount 44 ElseIf PrintForm.NumOptionButton Then 45 beginInt = PrintForm.FromTextBox 46 endInt = PrintForm.ToTextBox 47 End If 48 If beginInt > rowCount Then 49 MsgBox ("没有需要打印的数据!") 50 Exit Sub 51 End If 52 If endInt > rowCount Then 53 endInt = rowCount 54 End If 55 Worksheets("学生信息打印模板").Visible = True 56 '弹出打印提示窗口 57 '循环1--行 58 For ro = beginInt To endInt 59 '循环2--列 填写学生模板信息-->生成新的Excel 60 For col = 1 To columnCount 61 Title = Sheets(XsXxSheet).Cells(1, col) 62 If Title <> "" Then 63 Dim content As String 64 content = Sheets(XsXxSheet).Cells(ro, col) 65 Dim exl As TypeValueCell 66 exl.cellName = Title 67 exl.cellContent = content 68 aa = fileXsExportModel(exl) 69 End If 70 Next col 71 Worksheets("学生信息打印模板").PrintOut 72 Next ro 73 '清空模板 74 For col = 1 To columnCount 75 Title = Sheets(XsXxSheet).Cells(1, col) 76 If Title <> "" Then 77 Dim content2 As String 78 content2 = Sheets(XsXxSheet).Cells(2, col) 79 Dim exl2 As TypeValueCell 80 exl2.cellName = Title 81 exl2.cellContent = content1 82 bb = clearXsExportModel(exl2) 83 End If 84 Next col 85 Worksheets("学生信息打印模板").Visible = False 86 End Sub