Export Data To Excel
-
Hi, I need to export data from a dataset (datatable) into Excel or csv format. Can anyone help me out with this. With Best Regards, Mayur -- modified at 0:02 Thursday 16th February, 2006
-
Hi, I need to export data from a dataset (datatable) into Excel or csv format. Can anyone help me out with this. With Best Regards, Mayur -- modified at 0:02 Thursday 16th February, 2006
You should search the articles and forums on this website. I found some hits on my first try. Look at these... http://www.codeproject.com/aspnet/ExportClassLibrary.asp[^] http://www.codeproject.com/dotnet/ExportToExcel.asp[^] http://www.codeproject.com/useritems/excelxmlreport.asp[^]
-
You should search the articles and forums on this website. I found some hits on my first try. Look at these... http://www.codeproject.com/aspnet/ExportClassLibrary.asp[^] http://www.codeproject.com/dotnet/ExportToExcel.asp[^] http://www.codeproject.com/useritems/excelxmlreport.asp[^]
Are there any examples for vb.net With Best Regards, Mayur
-
Are there any examples for vb.net With Best Regards, Mayur
Hi You need to add a reference to Microsoft Excel 10 Object Library. There are other examples where you do not use the com object, which have the advantage that Excel does not need to be installed on the target machine. Then:
Private Sub ExportExcel(ByRef dt As DataTable) Dim excelApp As New Excel.Application Dim excelBook As Excel.Workbook = excelApp.Workbooks.Add Dim excelWorksheet As Excel.Worksheet = _ CType(excelBook.Worksheets(1), Excel.Worksheet) Dim dr As DataRow Dim Row As Integer = 1 Dim Col As Integer = 1 excelApp.Visible = False If dt.Rows.Count > 65536 Then MessageBox.Show("Warning - Excel sheet can only have 65536 Rows" _ & ControlChars.NewLine & ControlChars.NewLine _ & 65536 - dt.Rows.Count & " Rows will be omitted") End If If dt.Columns.Count > 256 Then MessageBox.Show("Warning - Excel sheet can only have 256 Rows" _ & ControlChars.NewLine & ControlChars.NewLine _ & 256 - dt.Columns.Count & " Columns will be omitted") End If With excelWorksheet 'Headings For Col = 0 To dt.Columns.Count - 1 .Cells(1, Col + 1).Value = dt.Columns(Col).ColumnName .Cells(1, Col + 1).Font.Bold = True .Cells(1, Col + 1).ColumnWidth = Len(dt.Columns(Col).ColumnName) + 3 Next .Range("A:Z").NumberFormat = "@" '(Text Format...) Row = 2 Col = 0 'Data Do While Row < dt.Rows.Count - 1 And Row < 65536 Do While Col <= dt.Columns.Count - 1 And Col < 255 .Cells(Row, Col + 1) = dt.Rows(Row - 2).Item(Col) Col += 1 Loop Col = 0 Row += 1 Loop End With excelApp.Visible = True End Sub
-- modified at 4:37 Thursday 16th February, 2006 -
Are there any examples for vb.net With Best Regards, Mayur
-
Hi You need to add a reference to Microsoft Excel 10 Object Library. There are other examples where you do not use the com object, which have the advantage that Excel does not need to be installed on the target machine. Then:
Private Sub ExportExcel(ByRef dt As DataTable) Dim excelApp As New Excel.Application Dim excelBook As Excel.Workbook = excelApp.Workbooks.Add Dim excelWorksheet As Excel.Worksheet = _ CType(excelBook.Worksheets(1), Excel.Worksheet) Dim dr As DataRow Dim Row As Integer = 1 Dim Col As Integer = 1 excelApp.Visible = False If dt.Rows.Count > 65536 Then MessageBox.Show("Warning - Excel sheet can only have 65536 Rows" _ & ControlChars.NewLine & ControlChars.NewLine _ & 65536 - dt.Rows.Count & " Rows will be omitted") End If If dt.Columns.Count > 256 Then MessageBox.Show("Warning - Excel sheet can only have 256 Rows" _ & ControlChars.NewLine & ControlChars.NewLine _ & 256 - dt.Columns.Count & " Columns will be omitted") End If With excelWorksheet 'Headings For Col = 0 To dt.Columns.Count - 1 .Cells(1, Col + 1).Value = dt.Columns(Col).ColumnName .Cells(1, Col + 1).Font.Bold = True .Cells(1, Col + 1).ColumnWidth = Len(dt.Columns(Col).ColumnName) + 3 Next .Range("A:Z").NumberFormat = "@" '(Text Format...) Row = 2 Col = 0 'Data Do While Row < dt.Rows.Count - 1 And Row < 65536 Do While Col <= dt.Columns.Count - 1 And Col < 255 .Cells(Row, Col + 1) = dt.Rows(Row - 2).Item(Col) Col += 1 Loop Col = 0 Row += 1 Loop End With excelApp.Visible = True End Sub
-- modified at 4:37 Thursday 16th February, 2006Can you give me some more input on not having Excel loading on the target machine. Below is a link to a question I had, the feedback I'm getting is you need to have Excel loaded. Can you give me more feedback on not having Excel loaded? http://www.codeproject.com/script/comments/forums.asp?msg=1396040&forumid=1646&mode=all&userid=387911#xx1396040xx[^] Lost in the vast sea of .NET