bah_jaf
سه شنبه 21 آبان 1387, 15:10 عصر
سلام دوستان در زیر یک کلاس هست که وقتی یک شی از نوع دیتا گرید ویو بگیره یک فایل اکسل ازش درست میکنه.
اگر کسی از اساتید هم نظر سازنده ای داره خوشحال میشم بشنوم.
نحوه صدا زدنش هم بصورت زیر هست :
ExportExcel.Make(mygrdview1) 'Call
Public
Class ExportExcel
SharedFunction Make(ByVal Grd As System.Windows.Forms.DataGridView) AsBoolean
Dim oldCI As System.Globalization.CultureInfo
oldCI = System.Threading.Thread.CurrentThread.CurrentCultu re
System.Threading.Thread.CurrentThread.CurrentCultu re = _
New System.Globalization.CultureInfo("en-US")
Dim x AsNew System.Windows.Forms.SaveFileDialog
x.Filter = "Excel File(*.XLS)|*.xls"
x.FileName =
"Report"
Dim Answer AsInteger = x.ShowDialog()
If Answer = 2 Then ReturnFalse
Dim oExcel AsObject
Dim oWorkBook AsObject
Dim oSheet AsObject
oExcel = CreateObject(
"Excel.Application")
oWorkBook = oExcel.Workbooks.Add
oExcel.visible = False
'For i AsInteger = 0 To Grd.ColumnCount - 1
oSheet.cells(1, i + 1) = Grd.Columns(i).HeaderText
oSheet.cells(1, i + 1).font.name = "Thahoma"
oSheet.cells(1, i + 1).font.bold =
True
Next
For j AsInteger = 0 To Grd.ColumnCount - 1
For i AsInteger = 0 To Grd.RowCount - 1
oSheet.cells(i + 2, j + 1) = Grd.Item(j, i).Value
oSheet.cells(i + 2, j + 1).font.name = "Thahoma"
Next
Next
'oSheet.Application.Visible = True
oSheet.SaveAs(x.FileName)
oSheet = Nothing
oWorkBook =
Nothing
oExcel.quit()
oExcel = Nothing
Return True
End Function
End Class
اگر کسی از اساتید هم نظر سازنده ای داره خوشحال میشم بشنوم.
نحوه صدا زدنش هم بصورت زیر هست :
ExportExcel.Make(mygrdview1) 'Call
Public
Class ExportExcel
SharedFunction Make(ByVal Grd As System.Windows.Forms.DataGridView) AsBoolean
Dim oldCI As System.Globalization.CultureInfo
oldCI = System.Threading.Thread.CurrentThread.CurrentCultu re
System.Threading.Thread.CurrentThread.CurrentCultu re = _
New System.Globalization.CultureInfo("en-US")
Dim x AsNew System.Windows.Forms.SaveFileDialog
x.Filter = "Excel File(*.XLS)|*.xls"
x.FileName =
"Report"
Dim Answer AsInteger = x.ShowDialog()
If Answer = 2 Then ReturnFalse
Dim oExcel AsObject
Dim oWorkBook AsObject
Dim oSheet AsObject
oExcel = CreateObject(
"Excel.Application")
oWorkBook = oExcel.Workbooks.Add
oExcel.visible = False
'For i AsInteger = 0 To Grd.ColumnCount - 1
oSheet.cells(1, i + 1) = Grd.Columns(i).HeaderText
oSheet.cells(1, i + 1).font.name = "Thahoma"
oSheet.cells(1, i + 1).font.bold =
True
Next
For j AsInteger = 0 To Grd.ColumnCount - 1
For i AsInteger = 0 To Grd.RowCount - 1
oSheet.cells(i + 2, j + 1) = Grd.Item(j, i).Value
oSheet.cells(i + 2, j + 1).font.name = "Thahoma"
Next
Next
'oSheet.Application.Visible = True
oSheet.SaveAs(x.FileName)
oSheet = Nothing
oWorkBook =
Nothing
oExcel.quit()
oExcel = Nothing
Return True
End Function
End Class