3.1.2 连接 Set xlsApp =CreateObject("Excel.Application") 内容来自论文无忧网 www.paper51.com Set XLSBOOK = Nothing paper51.com Set xlssheet = Nothing paper51.com xlsApp.Visible = False '设置EXCEL不可见 copyright paper51.com MsgBox "excel已打开", vbOKCancel, "信息提示" 内容来自www.paper51.com Set XLSBOOK =xlsApp.Workbooks.Open(CommonDialog1.FileName) copyright paper51.com Set xlssheet =XLSBOOK.Worksheets("sheet1") 内容来自论文无忧网 www.paper51.com
3.1.3 将excel数据传递到vb 内容来自论文无忧网 www.paper51.com intlastcolnum = xlssheet.UsedRange.Columns.Count 内容来自www.paper51.com
intlastrownum = xlssheet.UsedRange.Rows.Count paper51.com MSFlexGrid1.Rows = intlastrownum + 1 paper51.com MSFlexGrid1.cols = intlastcolnum + 1 内容来自论文无忧网 www.paper51.com For intcounti = 1 To intlastrownum paper51.com blnnullrow = True 内容来自www.paper51.com For inti = 1 To intlastcolnum copyright paper51.com blnnullrow = False 内容来自论文无忧网 www.paper51.com Next inti paper51.com
'若不是空行,则进行读取动作,否则继续向后遍历excel中的行 http://www.paper51.com If blnnullrow = False Then copyright paper51.com
For i = 1 To intlastrownum copyright paper51.com For j = 1 To intlastcolnum paper51.com MSFlexGrid1.TextMatrix(i, j) = xlssheet.Cells(i, j).Value 内容来自论文无忧网 www.paper51.com Next j paper51.com Next i http://www.paper51.com End If http://www.paper51.com
Next intcounti 内容来自www.paper51.com For i = 1 To intlastrownum copyright paper51.com MSFlexGrid1.TextMatrix(i, 0) = i http://www.paper51.com Next i 内容来自论文无忧网 www.paper51.com 3.1.4 将vb计算后的数据传递到excel 便于保存 内容来自论文无忧网 www.paper51.com 以下为积差相关分析窗口jxcg form中Command7、名称为数据送excel的代码: paper51.com 其功能是将vb的MSFlexGrid1控件里的数据导出到excel,便于保存。 paper51.com Set xlsApp =CreateObject("Excel.Application") '创建EXCEL应用类 paper51.com Set XLSBOOK = xlsApp.Workbooks.Add '打开EXCEL工作簿 copyright paper51.com Set xlssheet =XLSBOOK.Sheets("Sheet1") http://www.paper51.com Set xlssheet2 =XLSBOOK.Sheets("Sheet2") copyright paper51.com xlsApp.Visible = True '设置EXCEL可见 copyright paper51.com Set xlssheet = XLSBOOK.Worksheets("Sheet1") http://www.paper51.com intlastrownum =MSFlexGrid1.Rows - 1 copyright paper51.com
intlastcolnum =MSFlexGrid1.cols - 1 http://www.paper51.com For j = 0 ToMSFlexGrid1.Rows - 1 copyright paper51.com
For m = 0 To MSFlexGrid1.cols- 1 paper51.com xlssheet.Cells(j+1,m+1).Value =MSFlexGrid1.TextMatrix(j, m) http://www.paper51.com Next m 内容来自www.paper51.com Next j http://www.paper51.com 3.2 录入数据的实现 内容来自论文无忧网 www.paper51.com 以下为积差相关分析窗口jxcg form中Command1、名称为录入数据的代码: paper51.com Private Sub Command1_Click()’录入数据 copyright paper51.com MSFlexGrid1.TextMatrix(0, 0)= "学号" http://www.paper51.com
Text4.Text = InputBox("请输入科目数:", "数据输入","") paper51.com Text2.Text = InputBox("请输入学生人数:", "数据输入","") copyright paper51.com
MSFlexGrid1.Rows =Text2.Text + 5 copyright paper51.com MSFlexGrid1.cols =Text4.Text + 1 http://www.paper51.com n = Text2.Text 内容来自www.paper51.com m = Text4.Text http://www.paper51.com s1 = 1 http://www.paper51.com For i = 1 To m http://www.paper51.com
s = 0 内容来自论文无忧网 www.paper51.com For j = 1 To n 内容来自论文无忧网 www.paper51.com s = s + 1 内容来自www.paper51.com MSFlexGrid1.TextMatrix(j, i)= InputBox("请输入第" & s & "个学生的第" & s1 & "门课程的分数:", "数据输入","") 内容来自论文无忧网 www.paper51.com MSFlexGrid1.TextMatrix(j, 0) = j http://www.paper51.com MSFlexGrid1.TextMatrix(0, i) ="课程" & i 内容来自论文无忧网 www.paper51.com Next j paper51.com
s1 = s1 + 1 copyright paper51.com
Next i http://www.paper51.com If i = s + 1 Then 内容来自www.paper51.com Exit Sub 内容来自论文无忧网 www.paper51.com End If http://www.paper51.com
End Sub 内容来自www.paper51.com |