السلام عليكم.اخواني كيف يمكن تصدير بينات شبكة الداتا غريد نحو الاكسل بحيث تكون كل البيانات في الاكسل نوع خطها Bold و الخلايا مسطرة مثل الصورة و يتم الحفظ ورقة الاكسل بدون تدخل مني في القرص c
استعمل هذا الكود وهو يرسل البيانات جيدا لكن حاولت تسطير ورقة الاكسل و الحفظ و لم استطع ذلك.بارك الله فيكم
استعمل هذا الكود وهو يرسل البيانات جيدا لكن حاولت تسطير ورقة الاكسل و الحفظ و لم استطع ذلك.بارك الله فيكم
كود :
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Export_Excel(DataGridView1)
End Sub
Private Sub Export_Excel(ByVal st As Object)
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 Excel.Workbook = xlApp.Workbooks.Add
Dim excelWorksheet As Excel.Worksheet = CType(excelBook.Worksheets(1), Excel.Worksheet)
xlApp.Visible = True
rowsTotal = st.RowCount
colsTotal = st.Columns.Count - 1
With excelWorksheet
.Cells.Select()
.Cells.Delete()
For iC = 0 To colsTotal
.Cells(1, iC + 1).Value = st.Columns(iC).HeaderText
Next
For I = 0 To rowsTotal - 1
For j = 0 To colsTotal
.Cells(I + 2, j + 1).value = st.Rows(I).Cells(j).Value
Next j
Next I
.Rows("1:1").Style.Font.Name = "Arial"
.Rows("1:1").Font.FontStyle = "Bold"
.Rows("1:1").Font.Size = 12
.Columns.HorizontalAlignment = 3
.Cells(j + 1).ColumnWidth = 10
.Cells.Columns.AutoFit()
.Cells.Select()
.Cells.EntireColumn.AutoFit()
.Cells(1, 1).Select()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
xlApp = Nothing
'xlApp.SaveAs("C:\Document_Admin.xlsx")
'xlApp.Close()
'xlApp.Quit()
End Try
End Sub