我看了一下你的代碼就是 導(dǎo)出當(dāng)前datagrid顯示記錄
10年的玉龍網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。網(wǎng)絡(luò)營銷推廣的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整玉龍建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。成都創(chuàng)新互聯(lián)從事“玉龍網(wǎng)站設(shè)計(jì)”,“玉龍網(wǎng)站推廣”以來,每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
Do While DataGrid1.Row = 0
If i = DataGrid1.Row Then Exit Do
i = DataGrid1.Row '得到DataGrid1當(dāng)前行
For j = 0 To DataGrid1.Columns.Count - 1 '在DataGrid1當(dāng)前行各列中循環(huán)
With xlsApp
'用長度做判斷是不是身份證號(hào),當(dāng)然這個(gè)不是最好的方法,一般應(yīng)該是固定那一列是身份證號(hào),所以最好如果是第五列那么 if j=4 then,替換下面這行
if len(DataGrid1.Columns(j).Text)=18 or len(DataGrid1.Columns(j).Text)=15 then
.Cells(1, j + 1).NumberFormatLocal = "@" '單元格設(shè)置為文本
end if
.Cells(DataGrid1.Row + 1, j + 1) = DataGrid1.Columns(j).Text '填充數(shù)據(jù)
End With
Next
DataGrid1.Row = DataGrid1.Row + 1
Loop
Public Class Cls導(dǎo)入數(shù)據(jù)
Dim xlApp As New Excel.Application()
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim A = "A"
Public Function 導(dǎo)出到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
Next
'得到的表所有行,賦值給單元格
For Each Row In Table.Rows
rowIndex = rowIndex + 1
colIndex = 0
For Each Col In Table.Columns
colIndex = colIndex + 1
xlApp.Cells(rowIndex, colIndex) = Row(Col.ColumnName)
Next
Next
With xlSheet
.Range(.Cells(1, 1), .Cells(1, colIndex)).Font.Name = "黑體"
'設(shè)標(biāo)題為黑體字
.Range(.Cells(1, 1), .Cells(1, colIndex)).Font.Bold = True
'標(biāo)題字體加粗
.Range(.Cells(1, 1), .Cells(rowIndex, colIndex)).Borders.LineStyle = 1
'設(shè)表格邊框樣式
End With
With xlSheet.PageSetup
.LeftHeader = "" Chr(10) """楷體_GB2312,常規(guī)""10公司名稱:" ' Gsmc
.CenterHeader = """楷體_GB2312,常規(guī)""公司人員情況表""宋體,常規(guī)""" Chr(10) """楷體_GB2312,常規(guī)""10日 期:"
.RightHeader = "" Chr(10) """楷體_GB2312,常規(guī)""10單位:"
.LeftFooter = """楷體_GB2312,常規(guī)""10制表人:"
.CenterFooter = """楷體_GB2312,常規(guī)""10制表日期:"
.RightFooter = """楷體_GB2312,常規(guī)""10第P頁 共N頁"
End With
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()
Next
End Sub
end class
有2個(gè)方案:
1、在導(dǎo)出前對(duì)數(shù)據(jù)進(jìn)行處理:在電話號(hào)碼前+上一個(gè)“'”(單引號(hào)),這樣excel就判定該數(shù)據(jù)是字符串,就不會(huì)轉(zhuǎn)化成科學(xué)計(jì)數(shù)法了。
2、可以建立一個(gè)導(dǎo)出文件的excel模板(excel文件是.xls,模板文件是.xlt文件),在模板里將要注入數(shù)據(jù)的單元格屬性設(shè)置成字符串型就可以了。
當(dāng)前文章:vb.net導(dǎo)出xls科學(xué)計(jì)數(shù)的簡單介紹
網(wǎng)頁URL:http://jinyejixie.com/article0/hejjio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、定制網(wǎng)站、網(wǎng)站制作、云服務(wù)器、網(wǎng)站設(shè)計(jì)公司、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)