Imports System.IO Public Class Convert_Deg Dim cad As String Dim area As String Dim rang As String Private Sub ConvertToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConvertToolStripMenuItem.Click Try For i = 0 To DataGridView1.Rows.Count - 1 Dim Degrees As Integer Degrees = DataGridView1.Rows(i).Cells(2).Value If DataGridView1.Rows(i).Cells(2).Value < Degrees Then Degrees = Degrees - 1 End If Dim Minutes = (DataGridView1.Rows(i).Cells(2).Value - Degrees) * 60 Dim Seconds = Format(((Minutes - Int(Minutes)) * 60), "0.00000") DataGridView1.Rows(i).Cells(0).Value = " " & Degrees & "° " & Int(Minutes) & "' " _ & Seconds + Chr(34) Next Catch ex As Exception End Try Try For i = 0 To DataGridView1.Rows.Count - 1 Dim Degrees1 As Integer Degrees1 = DataGridView1.Rows(i).Cells(3).Value If DataGridView1.Rows(i).Cells(3).Value < Degrees1 Then Degrees1 = Degrees1 - 1 End If Dim Minutes1 = (DataGridView1.Rows(i).Cells(3).Value - Degrees1) * 60 Dim Seconds1 = Format(((Minutes1 - Int(Minutes1)) * 60), "0.00000") DataGridView1.Rows(i).Cells(1).Value = " " & Degrees1 & "° " & Int(Minutes1) & "' " _ & Seconds1 + Chr(34) Next Catch ex As Exception End Try End Sub Private Sub CalculeazaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculeazaToolStripMenuItem.Click Dim dir As String Dim fileopen As New OpenFileDialog fileopen.Filter = "Excel files|*.xlsx;*.xls;|All|*.*" fileopen.ShowDialog() dir = fileopen.FileName cad = dir area = "sheet1" cag(cad, area, rang, DataGridView1) End Sub Private Function cag(ByVal cad As String, ByVal area As String, ByVal rang As String, ByVal data As DataGridView) Try If System.IO.File.Exists(cad) Then Dim objdataset As System.Data.DataSet Dim objadapter As System.Data.OleDb.OleDbDataAdapter 'Dim scs As String = "provider=Microsoft.jet.OLEDB.4.0;" & "data source=" & cad & "Extended properties = 8.0" Dim scs2010 As String = "provider=Microsoft.ACE.OLEDB.12.0;" & "data source=" & cad & ";Excel 12.0; IMEX = 1; HDR = YES;" Dim objtoconexion As System.Data.OleDb.OleDbConnection objtoconexion = New System.Data.OleDb.OleDbConnection(scs2010) Dim consulta As String = "select * from" & "[" & area & "$" & rang & "]" objadapter = New System.Data.OleDb.OleDbDataAdapter(consulta, objtoconexion) objdataset = New System.Data.DataSet objadapter.Fill(objdataset) objtoconexion.Close() With data .DataSource = objdataset .DataMember = objdataset.Tables(0).TableName End With Else MsgBox("teapa" & cad) End If Catch ex As Exception End Try End Function Public Sub Exportar_Excel(ByVal dgv As DataGridView, ByVal pth As String) Dim xlApp As Object = CreateObject("Excel.Application") 'crear una nueva hoja de calculo Dim xlWB As Object = xlApp.WorkBooks.add Dim xlWS As Object = xlWB.WorkSheets(1) 'exportamos los caracteres de las columnas For c As Integer = 0 To DataGridView1.Columns.Count - 1 xlWS.cells(1, c + 1).value = DataGridView1.Columns(c).HeaderText Next 'exportamos las cabeceras de columnas For r As Integer = 0 To DataGridView1.RowCount - 1 For c As Integer = 0 To DataGridView1.Columns.Count - 1 xlWS.cells(r + 2, c + 1).value = DataGridView1.Item(c, r).Value Next Next 'guardamos la hoja de calculo en la ruta especificada xlWB.saveas(pth) xlWS = Nothing xlWB = Nothing xlApp.quit() xlApp = Nothing End Sub Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveAsToolStripMenuItem.Click Dim save As New SaveFileDialog save.Filter = "Excel files| *.xlsx" If save.ShowDialog = Windows.Forms.DialogResult.OK Then Exportar_Excel(Me.DataGridView1, save.FileName) End If End Sub End Class