DataGrid中的数据倒入Excel
2005-08-19 10:20
309 查看
Private Sub btnInput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInput.Click
Dim App As New Excel.Application
Dim Wk As Excel.Workbook
Dim Ws As Excel.Worksheet
Dim openFile As OpenFileDialog = New OpenFileDialog
Dim filename As String
Dim iCount As Integer
Dim i As Int16
Dim Gstr As String
Dim strSql As String
Dim strSql1 As String
Dim dsSearch As DataSet
Try
openFile.DefaultExt = "xls"
openFile.Filter = "Word documents (*.xls)|*.xls"
openFile.ShowDialog()
If (openFile.FileNames.Length > 0) Then
For Each filename In openFile.FileNames
Wk = App.Workbooks.Open(filename)
Ws = Wk.Sheets("Sheet1")
iCount = App.ActiveSheet.usedrange.rows.count
ProgressBar1.Maximum = iCount
ProgressBar1.Minimum = 0
For i = 4 To App.ActiveSheet.usedrange.rows.count
strSql1 = "select * from DateReport where PeopleId='" & Ws.Cells(i, 3).value & "' and ProjId='" & Ws.Cells(i, 4).value & "' and WorkId='" & Ws.Cells(i, 5).value & "'" & " and DepartId='" & Ws.Cells(i, 1).value & "'"
dsSearch = QueryTable(strSql1)
If dsSearch.Tables(0).Rows.Count > 0 Then
strSql1 = "delete from DateReport where PeopleId='" & Ws.Cells(i, 3).value & "' and ProjId='" & Ws.Cells(i, 4).value & "' and WorkId='" & Ws.Cells(i, 5).value & "'" & " and DepartId='" & Ws.Cells(i, 1).value & "'"
executeSql(strSql1)
End If
strSql = "insert into DateReport(PeopleName,PeopleId,DepartId,ProjId,WorkId,PlanSDate,PlanEDate,FactSDate,FactFWork,AccidentId,IntendDate,Mark) values('" & _
Ws.Cells(i, 2).value & "','" & Ws.Cells(i, 3).value & "','" & Ws.Cells(i, 1).value & "','" & Ws.Cells(i, 4).value & "','" & Ws.Cells(i, 5).value & "','" & _
"20" & Ws.Cells(i, 6).value.ToString.Replace(".", "") & "','" & "20" & Ws.Cells(i, 7).value.ToString.Replace(".", "") & "','" & "20" & Ws.Cells(i, 8).value.ToString.Replace(".", "") & "','" & Ws.Cells(i, 9).value & "','" & Ws.Cells(i, 10).value & "','" & _
Ws.Cells(i, 11).value & "','" & Ws.Cells(i, 12).value & "')"
executeSql(strSql)
ProgressBar1.Value = iCount - i
Next
MessageBox.Show("获取记录成功")
'Wk.Close()
'wk=nothing
'App = Nothing
Next
End If
fillGrid()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
App.ActiveWorkbook.Close()
App.Workbooks.Close()
App.Quit()
Wk = Nothing
App = Nothing
GC.Collect()
End Try
End Sub
Dim App As New Excel.Application
Dim Wk As Excel.Workbook
Dim Ws As Excel.Worksheet
Dim openFile As OpenFileDialog = New OpenFileDialog
Dim filename As String
Dim iCount As Integer
Dim i As Int16
Dim Gstr As String
Dim strSql As String
Dim strSql1 As String
Dim dsSearch As DataSet
Try
openFile.DefaultExt = "xls"
openFile.Filter = "Word documents (*.xls)|*.xls"
openFile.ShowDialog()
If (openFile.FileNames.Length > 0) Then
For Each filename In openFile.FileNames
Wk = App.Workbooks.Open(filename)
Ws = Wk.Sheets("Sheet1")
iCount = App.ActiveSheet.usedrange.rows.count
ProgressBar1.Maximum = iCount
ProgressBar1.Minimum = 0
For i = 4 To App.ActiveSheet.usedrange.rows.count
strSql1 = "select * from DateReport where PeopleId='" & Ws.Cells(i, 3).value & "' and ProjId='" & Ws.Cells(i, 4).value & "' and WorkId='" & Ws.Cells(i, 5).value & "'" & " and DepartId='" & Ws.Cells(i, 1).value & "'"
dsSearch = QueryTable(strSql1)
If dsSearch.Tables(0).Rows.Count > 0 Then
strSql1 = "delete from DateReport where PeopleId='" & Ws.Cells(i, 3).value & "' and ProjId='" & Ws.Cells(i, 4).value & "' and WorkId='" & Ws.Cells(i, 5).value & "'" & " and DepartId='" & Ws.Cells(i, 1).value & "'"
executeSql(strSql1)
End If
strSql = "insert into DateReport(PeopleName,PeopleId,DepartId,ProjId,WorkId,PlanSDate,PlanEDate,FactSDate,FactFWork,AccidentId,IntendDate,Mark) values('" & _
Ws.Cells(i, 2).value & "','" & Ws.Cells(i, 3).value & "','" & Ws.Cells(i, 1).value & "','" & Ws.Cells(i, 4).value & "','" & Ws.Cells(i, 5).value & "','" & _
"20" & Ws.Cells(i, 6).value.ToString.Replace(".", "") & "','" & "20" & Ws.Cells(i, 7).value.ToString.Replace(".", "") & "','" & "20" & Ws.Cells(i, 8).value.ToString.Replace(".", "") & "','" & Ws.Cells(i, 9).value & "','" & Ws.Cells(i, 10).value & "','" & _
Ws.Cells(i, 11).value & "','" & Ws.Cells(i, 12).value & "')"
executeSql(strSql)
ProgressBar1.Value = iCount - i
Next
MessageBox.Show("获取记录成功")
'Wk.Close()
'wk=nothing
'App = Nothing
Next
End If
fillGrid()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
App.ActiveWorkbook.Close()
App.Workbooks.Close()
App.Quit()
Wk = Nothing
App = Nothing
GC.Collect()
End Try
End Sub
相关文章推荐
- 如何将DataGrid中的数据倒入到Excel (客户端)
- Winform下datagrid数据倒入excel
- datagrid数据导出到excel文件给客户端下载的几种方法
- flex 保存datagrid数据到excel中
- datagrid数据导出到excel文件给客户端下载的几种方法
- 把Excel文件中的数据读入到DataGrid中
- [转贴]将DataGrid中数据倒出Excel文件并下载
- 将datagrid数据导入到excel的方法
- 将DataGrid数据写入Excel文件
- 在网看到了一个Silverlight导出DataGrid里的数据到Excel或xml文件里
- 将Oracle的数据倒入EXCEL中的方法
- EXCEL的数据倒入到数据库
- 从Excel中读出数据并倒入sql2000中
- datagrid数据导出到excel文件给客户端下载的几种方法
- DataGrid系列技巧(导出excel,事件,多种方式呈现数据,全选全删)等等等 (转)
- datagrid数据导出到excel文件给客户端下载的几种方法
- datagrid数据导出到excel文件给客户端下载的几种方法
- asp.net中将DataGrid数据导出到excel或word文件中
- datagrid数据导出到excel文件给客户端下载的几种方法(转)
- DataGrid系列技巧(导出excel,事件,多种方式呈现数据,全选全删)等等等