8,737
社区成员
发帖
与我相关
我的任务
分享
'Dim i As Short
'Dim j As Short
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim xlsName As String
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim intColNum As Integer
Dim intRowNum As Integer
xlsName = My.Application.Info.DirectoryPath & "\IssSettDetails0754970089800019800000420110303.xls"
'用 Add方法 创建新的工作簿和工作表对象。
xlApp = New Microsoft.Office.Interop.Excel.Application
xlBook = xlApp.Workbooks.Open(xlsName)
xlSheet = xlBook.Worksheets("sheet1")
xlSheet.Name = "sheet1"
'xlAppExcelFile.ShowWindowsInTaskbar = False
xlSheet = xlBook.Sheets(1)
intRowNum = xlSheet.UsedRange.Rows.Count
intColNum = xlSheet.UsedRange.Columns.Count
' If Err.Number = 1004 Then
' xlSheet.Name = formatdatetime(DateTimePicker1, "yyyymm")
' MsgBox (DateTimePicker1 & "工作表已存在将自动产生sheel系列工作表")
' Err.Number = 0
' End If
'将data3的值赋给Microsoft Excel 单元。
'sqlString = "select * from worktable"
'If Conn.State = 1 Then
' If Rs.State = 1 Then Rs.Close()
' Rs.Open(sqlString, Conn, 1, 1)
'Else
' Conn.Open(conString)
' Rs.Open(sqlString, Conn, 1, 1)
'End If
'For i = 0 To 5
' For j = 0 To 7
' xlSheet.Cells._Default(i + 1, j + 1).Value = i & "," & j
' Next j
'Next i
'xlSheet.Cells(3, 1).Formula = "=R1C1 + R2C1"
'保存工作表
MessageBox.Show(xlSheet.Cells._Default(16, 8).Value.ToString + ":" + intColNum.ToString + ":" + intRowNum.ToString)
xlSheet.Cells._Default(18, 8).Value = 11
xlSheet.StandardWidth = 2
'xlSheet.SaveAs(App.path & "\" & FormatDateTime(DateTimePicker1, "yyyy年mm月值班表") & FormatDateTime(Now(), "hhmmss") & ".xls")
xlSheet.SaveAs("e:\1.xls")
xlBook.Save()
xlBook.Close()
'用 Quit 方法关闭 Microsoft Excel
xlApp.Quit()
'释放对象
Dim pro As Process
For Each pro In Process.GetProcesses
If pro.ProcessName = "EXCEL" Then
pro.Kill()
End If
Next
End Sub
Dim i As Short
Dim j As Short
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim xlsName As String
Private Sub Botton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
xlsName = My.Application.Info.DirectoryPath & "\temp.xls"
'用 Add方法 创建新的工作簿和工作表对象。
xlApp = New Microsoft.Office.Interop.Excel.Application
xlBook = xlApp.Workbooks.Open(xlsName)
'Set xlBook = xlApp.Workbooks.Add
xlSheet = xlBook.Worksheets("work")
xlSheet.Name = "work"
' If Err.Number = 1004 Then
' xlSheet.Name = formatdatetime(DateTimePicker1, "yyyymm")
' MsgBox (DateTimePicker1 & "工作表已存在将自动产生sheel系列工作表")
' Err.Number = 0
' End If
'将data3的值赋给Microsoft Excel 单元。
'sqlString = "select * from worktable"
'If Conn.State = 1 Then
' If Rs.State = 1 Then Rs.Close()
' Rs.Open(sqlString, Conn, 1, 1)
'Else
' Conn.Open(conString)
' Rs.Open(sqlString, Conn, 1, 1)
'End If
For i = 0 To 5
For j = 0 To 7
xlSheet.Cells._Default(i + 1, j + 1).Value = i & "," & j
Next j
Next i
'xlSheet.Cells(3, 1).Formula = "=R1C1 + R2C1"
'保存工作表
'xlSheet.StandardWidth = 2
'xlSheet.SaveAs (App.path & "\" & formatdatetime(DateTimePicker1, "yyyy年mm月值班表") & formatdatetime(Now(), "hhmmss") & ".xls")
xlBook.Save()
xlBook.Close()
'用 Quit 方法关闭 Microsoft Excel
xlApp.Quit()
'释放对象
Dim pro As Process
For Each pro In Process.GetProcesses
If pro.ProcessName = "EXCEL" Then
pro.Kill()
End If
Next