<DT>VB.NET code
<DD><!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
Imports System.Data
Imports System.Data.SqlClient
Partial Class addexcel
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If FileUpload1.PostedFile.ContentLength = 0 Then
Label1.Text = '<FONT COLOR=RED>上传失败或文件不存在!</FONT>'
ElseIf Right(FileUpload1.PostedFile.FileName, 4) <> '.xls' Then
Label1.Text = '<FONT COLOR=RED>文件格式错误!</FONT>'
Else
' 获取文件名()
Dim Temp() As String = Split(FileUpload1.PostedFile.FileName, '\')
Dim FileName As String = Temp(Temp.Length - 1)
'保存文件
FileUpload1.PostedFile.SaveAs(Server.MapPath('') & '/excel/lishi.xls')
'显示上传结果
Label1.Text = '文件上传成功!<br>上传文件:' & FileName
End If
Dim sql As String = 'select * from [Sheet1$]'
Dim conn As String = ' Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =' + Server.MapPath('') + '/excel/lishi.xls;Extended Properties=Excel 8.0'
Dim thisconnection As OleDb.OleDbConnection = New OleDb.OleDbConnection(conn)
thisconnection.Open()
Dim mycommand As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(sql, thisconnection)
Dim ds As New DataSet
mycommand.Fill(ds, '[Sheet1$]')
ds.Tables('[Sheet1$]').Columns.RemoveAt(12)
ds.Tables('[Sheet1$]').Columns.RemoveAt(11)
ds.Tables('[Sheet1$]').Columns.RemoveAt(10)
ds.Tables('[Sheet1$]').Columns.RemoveAt(9)
ds.Tables('[Sheet1$]').Columns.RemoveAt(8)
ds.Tables('[Sheet1$]').Columns.RemoveAt(7)
ds.Tables('[Sheet1$]').Columns.RemoveAt(6)
ds.Tables('[Sheet1$]').Columns.RemoveAt(5)
ds.Tables('[Sheet1$]').Columns.RemoveAt(4)
ds.Tables('[Sheet1$]').Columns.RemoveAt(2)
ds.Tables('[Sheet1$]').Columns.Add('部级核对')
ds.Tables('[Sheet1$]').Columns.Add('课级核对')
ds.Tables('[Sheet1$]').Columns.Add('组级核对')
thisconnection.Close()
GridView1.DataSource = ds
GridView1.DataBind()
Panel1.Visible = False
Panel2.Visible = True
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
Dim kk As New renzibll
If e.Row.RowIndex > -1 Then
If e.Row.Cells(3).Text <> '' Then
e.Row.Cells(6).Text = kk.Getbu(e.Row.Cells(3).Text)
End If
If e.Row.Cells(4).Text <> '' Then
e.Row.Cells(7).Text = kk.GetKe(Replace(e.Row.Cells(4).Text, '课', ''))
End If
If e.Row.Cells(5).Text <> '' Then
e.Row.Cells(8).Text = kk.GetZu(e.Row.Cells(5).Text)
End If
If e.Row.Cells(6).Text = '' Or e.Row.Cells(7).Text = '' Or e.Row.Cells(8).Text = '' Then
Button2.Enabled = False
Button2.Text = '请修正核对部门'
End If
End If
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sql As String = 'select * from [Sheet1$]'
Dim conn As String = ' Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =' + Server.MapPath('') + '/excel/lishi.xls;Extended Properties=Excel 8.0'
Dim thisconnection As OleDb.OleDbConnection = New OleDb.OleDbConnection(conn)
thisconnection.Open()
Dim mycommand As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(sql, thisconnection)
Dim ds As New DataSet
mycommand.Fill(ds, '[Sheet1$]')
thisconnection.Close()
Dim i = 0, rowcount As Integer = ds.Tables('[Sheet1$]').Rows.Count
Dim tt As New renzibll
Try
tt.ini()
For i = 0 To rowcount - 1
If GridView1.Rows(i).Cells(8).Text <> '' Then
tt.zu_add(GridView1.Rows(i).Cells(8).Text, GridView1.Rows(i).Cells(3).Text)
End If
Next
Catch ex As Exception
Response.Write(ex)
End Try
Dim ll As New linshi
ll.IsUpdate()
Panel2.Visible = False
Panel3.Visible = True
End Sub
Protected Sub GridView2_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView2.RowDataBound
If e.Row.RowIndex > -1 Then
e.Row.Cells(10).Text = Format(Convert.ToDateTime(e.Row.Cells(10).Text), 'yyyy年MM月dd日')
If e.Row.Cells(5).Text = 1 Then
e.Row.Cells(5).Text = '是'
Else