Escolar Documentos
Profissional Documentos
Cultura Documentos
String)
Dim m_Excel As New Excel.Application
m_Excel.Cursor = Excel.XlMousePointer.xlWait
m_Excel.Visible = True
Dim objLibroExcel As Excel.Workbook = m_Excel.Workbooks.Add
Dim objHojaExcel As Excel.Worksheet = objLibroExcel.Worksheets(1)
With objHojaExcel
.Visible = Excel.XlSheetVisibility.xlSheetVisible
.Activate()
'Encabezado
.Range("A1:L1").Merge()
.Range("A1:L1").Value = "INSTITUTO ARGENCAF"
.Range("A1:L1").Font.Bold = True
.Range("A1:L1").Font.Size = 15
'Copete
.Range("A2:L2").Merge()
.Range("A2:L2").Value = titulo
.Range("A2:L2").Font.Bold = True
.Range("A2:L2").Font.Size = 12
'CARGA DE DATOS
Dim i As Integer = Numero + 1
End If
Next
Dim objRangoReg As Excel.Range = .Range(primeraLetra +
i.ToString, strColumna + i.ToString)
objRangoReg.Rows.BorderAround()
objRangoReg.Select()
i += 1
Next
UltimoNumero = i
objRango.Select()
objRango.Columns.AutoFit()
objRango.Columns.BorderAround(1, Excel.XlBorderWeight.xlMedium)
End With
m_Excel.Cursor = Excel.XlMousePointer.xlDefault
End Sub
___________________________________________________________________________________
________
Try
exLibro = exApp.Workbooks.Add
exHoja = exLibro.Worksheets.Add()
Next
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error al exportar a Excel")
Return False
End Try
Return True
End Function
________________________________________________________________________________
Try
'A�adimos el Libro al programa, y la hoja al libro
exLibro = exApp.Workbooks.Add
exHoja = exLibro.Worksheets.Add()
'Aqui recorremos todas las filas, y por cada fila todas las columnas y vamos
escribiendo.
For i As Integer = 1 To NCol
exHoja.Cells.Item(1, i) = ElGrid.Columns(i - 1).Name.ToString
'exHoja.Cells.Item(1, i).HorizontalAlignment = 3
Next
exHoja = Nothing
exLibro = Nothing
exApp = Nothing
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error al exportar a Excel")
'http://programaciontotal.blogspot.com
Return False
End Try
Return True
End Function
GridAExcel(nombreDeTuGrid)
_________________________________________________________________
End Try
Next
DTB.Rows.Add(DRW)
Next
DTB.AcceptChanges()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
__________________________________________
Imports System.IO
Imports Excel = Microsoft.Office.Interop.Excel
sub export
Dim default_location As String = Application.StartupPath & "\Jadwal\" &
periode.Text & ".xls"
'Creating dataset to export
Dim dset As New DataSet
'add table to dataset
dset.Tables.Add()
'add column to that table
For i As Integer = 0 To dg2.ColumnCount - 1
dset.Tables(0).Columns.Add(dg2.Columns(i).HeaderText)
Next
'add rows to the table
Dim dr1 As DataRow
For i As Integer = 0 To dg2.RowCount - 1
dr1 = dset.Tables(0).NewRow
For j As Integer = 0 To dg2.Columns.Count - 1
dr1(j) = dg2.Rows(i).Cells(j).Value
Next
dset.Tables(0).Rows.Add(dr1)
Next
excel.Visible = True
excel.UserControl = True
wBook = excel.Workbooks.Add(System.Reflection.Missing.Value)
wSheet = wBook.Sheets("sheet1")
excel.Range("A50:I50").EntireColumn.AutoFit()
With wBook
.Sheets("Sheet1").Select()
.Sheets(1).Name = "NameYourSheet"
End With
For i = 0 To dg2.RowCount - 1
For j = 0 To dg2.ColumnCount - 1
wSheet.Cells(i + 1, j + 1).value = dg2.Rows(i).Cells(j).Value.tosring
Next j
Next i
wSheet.Columns.AutoFit()
Dim blnFileOpen As Boolean = False
Try
Dim fileTemp As System.IO.FileStream = System.IO.File.OpenWrite(default_location)
fileTemp.Close()
Catch ex As Exception
blnFileOpen = False
End Try
If System.IO.File.Exists(default_location) Then
System.IO.File.Delete(default_location)
End If
wBook.SaveAs(default_location)
excel.Workbooks.Open(default_location)
excel.Visible = True
end sub
___________________________________________________________________
__________________________________________________________________________
_________________________________________________________