Click here to Skip to main content
15,892,805 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralSMTP vrs Proxy server Pin
plural31-Mar-08 21:10
plural31-Mar-08 21:10 
GeneralRe: SMTP vrs Proxy server Pin
Dave Kreskowiak1-Apr-08 10:29
mveDave Kreskowiak1-Apr-08 10:29 
Questionhow to identify tab key press in vb.net Pin
codelinks31-Mar-08 20:56
codelinks31-Mar-08 20:56 
AnswerRe: how to identify tab key press in vb.net Pin
christoph3331-Mar-08 22:20
christoph3331-Mar-08 22:20 
QuestionHow to create Pdf in windows application? Pin
Piyush Vardhan Singh31-Mar-08 19:18
Piyush Vardhan Singh31-Mar-08 19:18 
AnswerRe: How to create Pdf in windows application? Pin
Mitch F.31-Mar-08 20:16
Mitch F.31-Mar-08 20:16 
GeneralRe: How to create Pdf in windows application? Pin
Piyush Vardhan Singh31-Mar-08 23:19
Piyush Vardhan Singh31-Mar-08 23:19 
GeneralExport Data from datagrid to excel and open it Pin
herag31-Mar-08 16:53
herag31-Mar-08 16:53 
Hi everyone,
I have data from my server using sql data. I had the problem to export my data from datagrid to excel. For 200 data is oke, no problem but more than 200 , the program is stuck. Anybody can help me to solve this problem ???? Confused | :confused:

Private Sub ToolStripexport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripexport.Click
If (Me.dbgridinv Is Nothing) Then
Throw New ArgumentNullException("No DataGridView was provided for export")
End If
Using saveFileDialog As SaveFileDialog = Me.GetExcelSaveFileDialog
If (saveFileDialog.ShowDialog(Me) = DialogResult.OK) Then
Dim fileName As String = saveFileDialog.FileName
ExcelGenerator.Generate(Me.dbgridinv).Save(fileName)
Process.Start(fileName)
End If
End Using
End Sub

---------------------------------------------------
Imports CarlosAg.ExcelXmlWriter
Imports System
Imports System.Drawing
Imports System.Windows.Forms

Public Class ExcelGenerator
' Methods
Public Shared Function Generate(ByVal dataGridView As DataGridView) As Workbook
Dim workbook As New Workbook
Dim worksheet As Worksheet = workbook.Worksheets.Add("Sheet 1")
Dim worksheetRow As New WorksheetRow
Dim dataGridViewColumn As DataGridViewColumn
For Each dataGridViewColumn In dataGridView.Columns
worksheet.Table.Columns.Add(New WorksheetColumn(dataGridViewColumn.Width))
worksheetRow.Cells.Add(New WorksheetCell(dataGridViewColumn.HeaderText))
Next
worksheet.Table.Rows.Insert(0, worksheetRow)
Dim worksheetDefaultStyle As WorksheetStyle = ExcelGenerator.GetWorksheetStyle(dataGridView.DefaultCellStyle, "Default")
workbook.Styles.Add(worksheetDefaultStyle)
Dim rowIndex As Integer
For rowIndex = 0 To dataGridView.RowCount - 1
worksheetRow = worksheet.Table.Rows.Add
Dim columnIndex As Integer
For columnIndex = 0 To dataGridView.ColumnCount - 1
Dim cell As DataGridViewCell = dataGridView.Item(columnIndex, rowIndex)
Dim cellStyle As WorksheetStyle = ExcelGenerator.GetWorksheetStyle(cell.InheritedStyle, String.Concat(New Object() {"column", columnIndex, "row", rowIndex}))
If (Not cellStyle Is Nothing) Then
workbook.Styles.Add(cellStyle)
Else
cellStyle = worksheetDefaultStyle
End If
Dim dataType As DataType = ExcelGenerator.GetDataType(cell.ValueType)
worksheetRow.Cells.Add(cell.FormattedValue.ToString, dataType, cellStyle.ID)
Next columnIndex
Next rowIndex
Return workbook
End Function

Private Shared Function GetColorName(ByVal color As Color) As String
Return ("#" & color.ToArgb.ToString("X").Substring(2))
End Function

Private Shared Function GetDataType(ByVal valueType As Type) As DataType
If (Not valueType Is GetType(DateTime)) Then
If (valueType Is GetType(String)) Then
Return DataType.String
End If
If ((((((valueType Is GetType(SByte)) OrElse (valueType Is GetType(Byte))) OrElse ((valueType Is GetType(Short)) OrElse (valueType Is GetType(UInt16)))) OrElse (((valueType Is GetType(Integer)) OrElse (valueType Is GetType(UInt32))) OrElse ((valueType Is GetType(Long)) OrElse (valueType Is GetType(UInt64))))) OrElse ((valueType Is GetType(Single)) OrElse (valueType Is GetType(Double)))) OrElse (valueType Is GetType(Decimal))) Then
Return DataType.Number
End If
End If
Return DataType.String
End Function

Private Shared Function GetWorksheetStyle(ByVal dataGridViewCellStyle As DataGridViewCellStyle, ByVal id As String) As WorksheetStyle
Dim worksheetStyle As WorksheetStyle = Nothing
If (Not dataGridViewCellStyle Is Nothing) Then
worksheetStyle = New WorksheetStyle(id)
If Not dataGridViewCellStyle.BackColor.IsEmpty Then
worksheetStyle.Interior.Color = ExcelGenerator.GetColorName(dataGridViewCellStyle.BackColor)
worksheetStyle.Interior.Pattern = StyleInteriorPattern.Solid
End If
If Not dataGridViewCellStyle.ForeColor.IsEmpty Then
worksheetStyle.Font.Color = ExcelGenerator.GetColorName(dataGridViewCellStyle.ForeColor)
End If
If (Not dataGridViewCellStyle.Font Is Nothing) Then
worksheetStyle.Font.Bold = dataGridViewCellStyle.Font.Bold
worksheetStyle.Font.FontName = dataGridViewCellStyle.Font.Name
worksheetStyle.Font.Italic = dataGridViewCellStyle.Font.Italic
worksheetStyle.Font.Size = CInt(dataGridViewCellStyle.Font.Size)
worksheetStyle.Font.Strikethrough = dataGridViewCellStyle.Font.Strikeout
worksheetStyle.Font.Underline = IIf(dataGridViewCellStyle.Font.Underline, UnderlineStyle.Single, UnderlineStyle.None)
End If
worksheetStyle.Borders.Add(StylePosition.Top, LineStyleOption.Continuous, 1, "Black")
worksheetStyle.Borders.Add(StylePosition.Right, LineStyleOption.Continuous, 1, "Black")
worksheetStyle.Borders.Add(StylePosition.Bottom, LineStyleOption.Continuous, 1, "Black")
worksheetStyle.Borders.Add(StylePosition.Left, LineStyleOption.Continuous, 1, "Black")
End If
Return worksheetStyle
End Function

End Class
D'Oh! | :doh:
GeneralKeyDown method question Pin
sa_runner31-Mar-08 15:42
sa_runner31-Mar-08 15:42 
GeneralRe: KeyDown method question Pin
nlarson1131-Mar-08 17:09
nlarson1131-Mar-08 17:09 
GeneralRe: KeyDown method question Pin
GuyThiebaut31-Mar-08 23:33
professionalGuyThiebaut31-Mar-08 23:33 
Questionvb.net uploading values, data from application to website Pin
Ismaeel31-Mar-08 15:10
Ismaeel31-Mar-08 15:10 
GeneralRe: vb.net uploading values, data from application to website Pin
Eduard Keilholz31-Mar-08 23:52
Eduard Keilholz31-Mar-08 23:52 
GeneralSaveFileDialog help needed! Pin
jojoStoneHead31-Mar-08 13:54
jojoStoneHead31-Mar-08 13:54 
GeneralRe: SaveFileDialog help needed! Pin
Mitch F.31-Mar-08 14:13
Mitch F.31-Mar-08 14:13 
GeneralRe: SaveFileDialog help needed! Pin
jojoStoneHead31-Mar-08 14:17
jojoStoneHead31-Mar-08 14:17 
GeneralRe: SaveFileDialog help needed! Pin
Mitch F.31-Mar-08 14:27
Mitch F.31-Mar-08 14:27 
GeneralRe: SaveFileDialog help needed! Pin
Luc Pattyn31-Mar-08 14:46
sitebuilderLuc Pattyn31-Mar-08 14:46 
Questionget handlers from existing events in vb in an easy way Pin
christoph3331-Mar-08 3:49
christoph3331-Mar-08 3:49 
GeneralRe: get handlers from existing events in vb in an easy way Pin
MidwestLimey31-Mar-08 7:39
professionalMidwestLimey31-Mar-08 7:39 
AnswerRe: get handlers from existing events in vb in an easy way Pin
christoph3331-Mar-08 20:34
christoph3331-Mar-08 20:34 
GeneralRe: get handlers from existing events in vb in an easy way Pin
christoph3331-Mar-08 23:29
christoph3331-Mar-08 23:29 
GeneralRe: get handlers from existing events in vb in an easy way Pin
MidwestLimey1-Apr-08 5:32
professionalMidwestLimey1-Apr-08 5:32 
GeneralRe: get handlers from existing events in vb in an easy way Pin
christoph331-Apr-08 5:52
christoph331-Apr-08 5:52 
GeneralRe: get handlers from existing events in vb in an easy way Pin
MidwestLimey1-Apr-08 12:00
professionalMidwestLimey1-Apr-08 12:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.