Advertisement
Advertisement
| 06.09.2008 at 07:58AM PDT, ID: 23469273 |
|
[x]
Attachment Details
|
||
|
[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.
Your Input Matters 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! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: |
Private Sub ExportGridContentsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles ExportGridContentsToolStripMenuItem.Click
Dim strCSV As String = ""
Dim strFilename As String = ""
Dim swExport As StreamWriter
Dim intCount As Integer = 0
Dim intRow As Integer = 0
Dim intColumn As Integer = 0
SaveFileDialog1.Title = "Save File As "
SaveFileDialog1.InitialDirectory = defaultExportLocation
Try
With SaveFileDialog1
.Filter = "TXT files|*.txt|Excel 97-2003 Workbook|*.xls"
If .ShowDialog = Windows.Forms.DialogResult.OK Then
strFilename = .FileName
swExport = New StreamWriter(.OpenFile)
intCount = 0
Application.DoEvents()
Me.Cursor = Cursors.WaitCursor
If .FileName.Contains(".txt") Then
For Each dgColumn As DataGridViewTextBoxColumn In DataGridView1.Columns
If dgColumn.Index = 0 Then
strCSV = Chr(34) & dgColumn.HeaderText & Chr(34)
Else
strCSV = strCSV & ";" & Chr(34) & dgColumn.HeaderText & Chr(34)
End If
Next
swExport.WriteLine(strCSV)
For intRow = 0 To DataGridView1.RowCount - 2
strCSV = ""
For intColumn = 0 To DataGridView1.ColumnCount - 1
If intColumn = 0 Then
' first entry
strCSV = DataGridView1.Item(intColumn, intRow).Value.ToString
Else
strCSV = strCSV & ";" & DataGridView1.Item(intColumn, intRow).Value.ToString
End If
Next intColumn
' print contents of string here
swExport.WriteLine(strCSV)
intCount = intCount + 1
Next intRow
swExport.Close()
ElseIf .FileName.Contains(".xls") Then
Dim oXL As New Excel.Application
Dim oWB As Excel.Workbook = oXL.Workbooks.Add
Dim oSheet As Excel.Worksheet = CType(oWB.Worksheets.Add, Excel.Worksheet)
Dim intColumnMax, intRowMax As Integer
intRowMax = DataGridView1.Rows.Count - 1
intColumnMax = DataGridView1.Columns.Count - 1
For intRow = 0 To intRowMax
For intColumn = 0 To intColumnMax
oSheet.Cells(intRow + 1, intColumn + 1) = DataGridView1.Item(intColumn, intRow).Value.ToString
Next
intCount = intCount + 1
Next
oSheet.Columns.AutoFit()
oSheet.Activate()
If System.IO.File.Exists(.FileName) Then
oXL.DisplayAlerts = False
oXL.ActiveWorkbook.SaveAs(.FileName)
oXL.ActiveWorkbook.Close()
oXL.DisplayAlerts = True
Else
oSheet.SaveAs(.FileName)
End If
oXL.Quit()
oXL = Nothing
oWB = Nothing
oSheet = Nothing
End If
End If
End With
MsgBox(intCount & " records exported to file", MsgBoxStyle.OkOnly)
Me.Cursor = Cursors.Default
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
|