我看了一下你的代码就是 导出当前datagrid显示记录
Do While DataGrid1.Row = 0
If i = DataGrid1.Row Then Exit Do
i = DataGrid1.Row '得到DataGrid1当前行
For j = 0 To DataGrid1.Columns.Count - 1 '在DataGrid1当前行各列中循环
With xlsApp
.Cells(1, j + 1).NumberFormatLocal = "@" '单元格设置为文本
end if
.Cells(DataGrid1.Row + 1, j + 1) = DataGrid1.Columns(j).Text '填充数据
End With
Next
DataGrid1.Row = DataGrid1.Row + 1
Loop
Public Class Cls导入数据
Dim xlApp As New Excel.Application()
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim A = "A"
Public Function 导出到Excel(ByVal Dt表 As DataTable) As Boolean
Dim rowIndex, colIndex As Integer
rowIndex = 1
colIndex = 0
xlBook = xlApp.Workbooks().Add
xlSheet = xlBook.Worksheets("sheet1")
Dim Table As New DataTable()
Table = CreaTable()
'将所得到的表的列名,赋值给单元格
Dim Col As DataColumn
Dim Row As DataRow
For Each Col In Table.Columns
colIndex = colIndex + 1
xlApp.Cells(1, colIndex) = Col.ColumnName
'得到的表所有行,赋值给单元格
For Each Row In Table.Rows
rowIndex = rowIndex + 1
xlApp.Cells(rowIndex, colIndex) = Row(Col.ColumnName)
With xlSheet
.Range(.Cells(1, 1), .Cells(1, colIndex)).Font.Name = "黑体"
'设标题为黑体字
.Range(.Cells(1, 1), .Cells(1, colIndex)).Font.Bold = True
'标题字体加粗
.Range(.Cells(1, 1), .Cells(rowIndex, colIndex)).Borders.LineStyle = 1
'设表格边框样式
With xlSheet.PageSetup
xlApp.SaveWorkspace()
MsgBox("保存完毕", MsgBoxStyle.Exclamation, "提示")
KillAllExcels()
'xlApp.Visible = True
End Function
Sub KillAllExcels()
Dim proc As System.Diagnostics.Process
For Each proc In System.Diagnostics.Process.GetProcessesByName("EXCEL")
proc.Kill()
End Sub
end class
①.、在导出前对数据进行处理:在电话号码前+上一个"'"(单引号),这样excel就判定该数据是字符串,就不会转化成科学计数法了.
以上就是土嘎嘎小编为大家整理的vb.net导出xls科学计数的简单介绍vb.net导出xls科学计数的简单介绍相关咨询咨询主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!