以文本方式查看主题
- Foxtable(狐表) (http://foxtable.com/bbs/index.asp)
-- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2)
---- 求助 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=104975)
|
-- 作者:W1234
-- 发布时间:2017/8/9 14:53:00
-- 求助
[求助!我有两个EXCEL表(1.考试安排表,有姓名、身份证明号码、考试时间、考试地点等,2.考试成绩表,有姓名、身份证明号码、考试科目、考试成绩等)。请问怎样写代码将其不重复的导入一个FOXTABLE表(包含列名:姓名、身份证明号码、考试时间、考试地点、考试科目、考试成绩,并增加一列考试结果,60分以上为及格,60分以下为不及格)
|
-- 作者:有点甜
-- 发布时间:2017/8/9 15:59:00
--
1、合并数据
Dim dlg As New OpenFileDialog dlg.Filter = "Excel文件|*.xls;*.xlsx" If dlg.ShowDialog =DialogResult.OK Then Dim t As Table = Tables("表B") t.StopRedraw() Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) For n As Integer = 1 To Sheet.Rows.Count -1 Dim r As DataRow = t.DataTable.Find("第一列 = \'" & sheet(n, 0).text & "\'") If r Is Nothing Then r = t.DataTable.AddNew() For i As Integer = 0 To sheet.Cols.Count -1 Dim cname As String = sheet(0, i).text If t.Cols.Contains(cname) Then r(cname) = sheet(n, i).Text End If Next Next t.ResumeRedraw() End If
2、如果要处理考试结果,可以在datacolchanged事件,写代码
If e.DataCol.name = "考试成绩" Then If e.NewValue >= 60 Then e.DataRow("考试结果") = "合计" Else e.DataRow("考试结果") = "不合计" End If End If
|
-- 作者:W1234
-- 发布时间:2017/8/9 16:29:00
--
谢谢版主
|
-- 作者:W1234
-- 发布时间:2017/8/9 17:02:00
--
再次请教版主:我准备设计二个按钮分别将二EXCEL表的信息导入学员信息表(包含姓名、身份证明号码、考试时间、考试地点、考试科目、考试成绩、考试结果等列),先导入前四列的,再导入学员后三列的信息,应怎样写代码。谢谢
|
-- 作者:有点甜
-- 发布时间:2017/8/9 17:39:00
--
参考2楼代码。不会做上传具体项目。
|
-- 作者:W1234
-- 发布时间:2017/8/10 14:57:00
--
版主,再帮忙看看,怎样将两个EXCEL表的信息分别且不重复地导入到学员查询系统的学员考试信息中
|
-- 作者:有点甜
-- 发布时间:2017/8/10 15:26:00
--
导入代码
Dim dlg As New OpenFileDialog dlg.Filter = "Excel文件|*.xls;*.xlsx" If dlg.ShowDialog =DialogResult.OK Then Dim t As Table = Tables("学员考试信息") t.StopRedraw() Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) For n As Integer = 1 To Sheet.Rows.Count -1 Dim r As DataRow = t.DataTable.Find("身份证明号码 = \'" & sheet(n, 2).text & "\'") If r Is Nothing Then r = t.DataTable.AddNew() For i As Integer = 0 To sheet.Cols.Count -1 Dim cname As String = sheet(0, i).text If t.Cols.Contains(cname) Then r(cname) = sheet(n, i).Text End If Next Next t.ResumeRedraw() End If
DataColChanged事件
If e.DataCol.name = "考试成绩" Then If e.NewValue >= 60 Then e.DataRow("考试结果") = "合格" Else e.DataRow("考试结果") = "不合格" End If End If
|
-- 作者:W1234
-- 发布时间:2017/8/10 15:37:00
--
谢谢,谢谢!!!
|