12-11-13, 05:22 AM
بسم الله الرحمن الرحيم
فعلا روعة البرنامج يصدر HTML و RTF واذا تم اضافة تصدير البيانات على ملف اكسل بنفس تنسيق خلايا datagridview يكون ممتاز وانا احتاج فقط كيف يتيم تنسيف الخلايا ملف الاكسل بنفس تنسيق خلايا datagridview مع العلم استخدمت لتصدير الى الاكسل هذا الكود
فعلا روعة البرنامج يصدر HTML و RTF واذا تم اضافة تصدير البيانات على ملف اكسل بنفس تنسيق خلايا datagridview يكون ممتاز وانا احتاج فقط كيف يتيم تنسيف الخلايا ملف الاكسل بنفس تنسيق خلايا datagridview مع العلم استخدمت لتصدير الى الاكسل هذا الكود
كود :
Dim rowsTotal, colsTotal As Short
Dim I, j, iC As Short
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
Dim xlApp As New Excel.Application
Try
Dim excelBook As Microsoft.Office.Interop.Excel.Workbook = xlApp.Workbooks.Add
Dim excelWorksheet As Microsoft.Office.Interop.Excel.Worksheet = CType(excelBook.Worksheets(1), Excel.Worksheet)
xlApp.Visible = True
rowsTotal = DataGridView1.RowCount - 1
colsTotal = DataGridView1.Columns.Count - 1
Dim currCol As Integer = 1
With excelWorksheet
.Cells.Select()
.Cells.Delete()
For iC = 0 To colsTotal
If DataGridView1.Columns(iC).Visible = True Then
.Cells(1, currCol).Value = DataGridView1.Columns(iC).HeaderText
currCol = currCol + 1
End If
Next
For I = 0 To rowsTotal
currCol = 1
For j = 0 To colsTotal
If DataGridView1.Columns(j).Visible = True Then
.Cells(I + 2, currCol).value = DataGridView1.Rows(I).Cells(j).FormattedValue
currCol = currCol + 1
End If
Next j
Next I
.Rows("1:1").Font.FontStyle = "Bold"
.Rows("1:1").Font.Size = 10
.Cells.Columns.AutoFit()
.Cells.Select()
.Cells.EntireColumn.AutoFit()
.Cells(1, 1).Select()
End With
Catch ex As Exception
MsgBox("Export Excel Error " & ex.Message)
Finally
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
xlApp = Nothing
End Tryالله المستعان
