Advertisement

06.18.2008 at 07:30AM PDT, ID: 23495317
[x]
Attachment Details

export to multiple sheets

[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.4
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

Cursor.Current = System.Windows.Forms.Cursors.WaitCursor

Dim cnn As SqlConnection
Dim connectionString As String
Dim sql As String
Dim cnn1 As SqlConnection
Dim connectionString1 As String
Dim sql1 As String
Dim filename As String
Dim xlApp As New Microsoft.Office.Interop.Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim misValue As Object = System.Reflection.Missing.Value

xlApp = New Excel.ApplicationClass
xlWorkBook = xlApp.Workbooks.Add(misValue)

Dim Sheet1 As New Excel.Worksheet
Dim Sheet2 As New Excel.Worksheet
Dim Sheet3 As New Excel.Worksheet



xlApp.Workbooks.Add()


'=====================================================
' it creates the sheet1 containing Error Report Per File Type
'=====================================================

connectionString = "data source='" & ComboServers.Text & "'; Initial catalog=master;Integrated Security = True;"
cnn = New SqlConnection(connectionString)
cnn.Open()
sql = "Select [File Type],[Task],count(*) as [Error Count] from master.dbo.temp_Filter_by_error group by [File Type],[task] order by [File Type],[task]"
Dim dscmd As New SqlDataAdapter(sql, cnn)
Dim ds As New DataSet
dscmd.Fill(ds)


Dim Excel As Object = CreateObject("Excel.Application")
If Excel Is Nothing Then
MsgBox("It appears that Excel is not installed on this machine. This operation requires MS Excel to be installed on this machine.", MsgBoxStyle.Critical)
Return
End If


'Export to Excel process
Try
With Excel
.SheetsInNewWorkbook = 5
.Workbooks.Add()
.Worksheets(1).Select()


CType(Excel.Workbooks(1).Worksheets("Sheet1"), Microsoft.Office.Interop.Excel.Worksheet).Name = "Error Report Per File Type"

Dim i As Integer = 1
For col = 0 To ds.Tables(0).Columns.Count - 1
.cells(1, i).value = ds.Tables(0).Columns(col).ColumnName
.cells(1, i).EntireRow.Font.Bold = True
i += 1
Next
i = 2
Dim k As Integer = 1
For col = 0 To ds.Tables(0).Columns.Count - 1
i = 2
For row = 0 To ds.Tables(0).Rows.Count - 1
.Cells(i, k).Value = ds.Tables(0).Rows(row).ItemArray(col)
i += 1
Next
k += 1
Next
'filename = "c:\Exception Report " & Now().Year & "-" & Now().Month & "-" & Now().Day & " " & Now().Hour & " " & Now().Minute & " " & Now().Second & ".xls"
'.ActiveCell.Worksheet.SaveAs(filename)
End With
'System.Runtime.InteropServices.Marshal.ReleaseComObject(Excel)
'Excel = Nothing
' MsgBox("Exception errors have been exported succesfully to Excel. The report can be found at '" & filename & "'", MsgBoxStyle.Information)

Catch ex As Exception
MsgBox(ex.Message)
End Try



'=====================================================
' it creates the sheet2 containing Detailed Error Report
'=====================================================

connectionString1 = "data source='" & ComboServers.Text & "'; Initial catalog=master;Integrated Security = True;"
cnn1 = New SqlConnection(connectionString1)
cnn1.Open()
sql1 = "Select * from master.dbo.temp_Filter_by_error order by [Fileset ID],[Doc ID]"
Dim dscmd1 As New SqlDataAdapter(sql1, cnn1)
Dim ds1 As New DataSet
dscmd1.Fill(ds1)



'Export to Excel process
Try
With Excel
.SheetsInNewWorkbook = 1
.Workbooks.Add()
.Worksheets(1).Select()


CType(Excel.Workbooks(1).Worksheets("Sheet2"), Microsoft.Office.Interop.Excel.Worksheet).Name = "Detailed Error Report"

Dim i As Integer = 1
For col = 0 To ds1.Tables(0).Columns.Count - 1
.cells(1, i).value = ds1.Tables(0).Columns(col).ColumnName
.cells(1, i).EntireRow.Font.Bold = True
i += 1
Next
i = 2
Dim k As Integer = 1
For col = 0 To ds1.Tables(0).Columns.Count - 1
i = 2
For row = 0 To ds1.Tables(0).Rows.Count - 1
.Cells(i, k).Value = ds1.Tables(0).Rows(row).ItemArray(col)
i += 1
Next
k += 1
Next
'filename = "c:\Exception Report " & Now().Year & "-" & Now().Month & "-" & Now().Day & " " & Now().Hour & " " & Now().Minute & " " & Now().Second & ".xls"
'.ActiveCell.Worksheet.SaveAs(filename)
End With
'System.Runtime.InteropServices.Marshal.ReleaseComObject(Excel)
'Excel = Nothing
' MsgBox("Exception errors have been exported succesfully to Excel. The report can be found at '" & filename & "'", MsgBoxStyle.Information)

Catch ex As Exception
MsgBox(ex.Message)
End Try


' The excel is created and opened for insert value. We most close this excel using this system
'Dim pro() As Process = System.Diagnostics.Process.GetProcessesByName("EXCEL")
'For Each i As Process In pro
'i.Kill()
'Next


'=====================================================
' it creates the sheet3 containing Index Errors Report (if the user checks the checkbox
'=====================================================


If CheckBox1.CheckState = True Then

Dim cnn2 As SqlConnection
Dim connectionString2 As String
Dim sql2 As String

connectionString2 = "data source='" & ComboServers.Text & "'; Initial catalog=master;Integrated Security = True;"
cnn2 = New SqlConnection(connectionString2)
cnn2.Open()
sql2 = "Select * from master.dbo.temp_Filter_by_error where Task = 'Index Files' order by [Fileset ID],[Doc ID]"
Dim dscmd2 As New SqlDataAdapter(sql2, cnn2)
Dim ds2 As New DataSet
dscmd2.Fill(ds2)

Try
With Excel
.SheetsInNewWorkbook = 1
.Workbooks.Add()
.Worksheets(1).Select()


CType(Excel.Workbooks(1).Worksheets("Sheet3"), Microsoft.Office.Interop.Excel.Worksheet).Name = "Index Errors Report"

Dim i As Integer = 1
For col = 0 To ds2.Tables(0).Columns.Count - 1
.cells(1, i).value = ds2.Tables(0).Columns(col).ColumnName
.cells(1, i).EntireRow.Font.Bold = True
i += 1
Next
i = 2
Dim k As Integer = 1
For col = 0 To ds2.Tables(0).Columns.Count - 1
i = 2
For row = 0 To ds2.Tables(0).Rows.Count - 1
.Cells(i, k).Value = ds2.Tables(0).Rows(row).ItemArray(col)
i += 1
Next
k += 1
Next
'filename = "c:\Exception Report " & Now().Year & "-" & Now().Month & "-" & Now().Day & " " & Now().Hour & " " & Now().Minute & " " & Now().Second & ".xls"
'.ActiveCell.Worksheet.SaveAs(filename)
End With
'System.Runtime.InteropServices.Marshal.ReleaseComObject(Excel)
'Excel = Nothing
' MsgBox("Exception errors have been exported succesfully to Excel. The report can be found at '" & filename & "'", MsgBoxStyle.Information)

Catch ex As Exception
MsgBox(ex.Message)
End Try


End If

filename = "c:\Exception Report " & Now().Year & "-" & Now().Month & "-" & Now().Day & " " & Now().Hour & " " & Now().Minute & " " & Now().Second & ".xls"
Excel.ActiveCell.Worksheet.SaveAs(filename)

System.Runtime.InteropServices.Marshal.ReleaseComObject(Excel)
Excel = Nothing
MsgBox("Exception errors have been exported succesfully to Excel. The report can be found at '" & filename & "'", MsgBoxStyle.Information)


' The excel is created and opened for insert value. We most close this excel using this system
Dim pro() As Process = System.Diagnostics.Process.GetProcessesByName("EXCEL")
For Each i As Process In pro
i.Kill()
Next


End Sub



Your help will be greatly appreciated.

Thanks!

Tammy
 
 
 
Accepted Solution by jtammyg:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
20081119-EE-VQP-45 / EE_QW_2_20070628