我有以下vb6代码发送数据到excel表格,其中一个数字列格式化显示两位小数,一切正常,除非十进制数字以零结尾,excel显示只有一个小数位,如234.60 显示243.6我如何设法显示零
Private Sub Command41_Click()
Dim cno
Dim tex
Dim VatAmount As Double
Dim MyexceL As Excel.Application
Set MyexceL = New Excel.Application
Set MyexceL = New Excel.Application
MyexceL.Workbooks.Add
MyexceL.Cells(1, 1).Value = "THC VAT Invoices "
MyexceL.Cells(2, 3).Value = "D/O No. "
MyexceL.Cells(2, 4).Value = "Date "
MyexceL.Cells(2, 5).Value = "Clearing Agent "
MyexceL.Cells(2, 6).Value = "VAT "
tex = App.Path
tex = tex + "\delivery.mdb"
Set con = New ADODB.Connection
con.CursorLocation = adUseClient
con.Open " Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=contianersbakatl;Data Source=ACC-PC\SQLEXPRESS"
con.Execute "DELETE FROM MASTLOT"
'If Option1.Value = True Then
Dim Fdate, sdaTE
Fdate = Format(TXTDAte.Text, "mm/dd/yyyy")
sdaTE = Format(txtdate1.Text, "mm/dd/yyyy")
Set rs = New ADODB.Recordset
rs.Open "select * from delivery where del_date between '" & Fdate & "' and ' " & sdaTE & "' order by del_date ,DEL_sERIAL ", con, adOpenDynamic, adLockOptimistic
cno = 0
ccn = 2
While Not rs.EOF
cno = cno + 1
ccn = ccn + 1
MyexceL.Cells(ccn, 3).Value = rs!del_serial
MyexceL.Cells(ccn, 4).Value = CDate(rs!del_date)
MyexceL.Cells(ccn, 5).Value = rs!DEL_CLEARNAME
VatAmount = rs!del_discount * 100 / 117 * 17 / 100
MyexceL.Cells(ccn, 6).Value = Format(VatAmount, "#,##0.00")
rs.MoveNext
Wend
MyexceL.Visible = True
End Sub
答案 0 :(得分:2)
您需要设置单元格NumberFormat
,然后填充Value
:只是格式化实际值不会这样做。
With MyexceL.Cells(ccn, 6)
.NumberFormat = "#,##0.00"
.Value = VatAmount
End With
答案 1 :(得分:1)
我认为它的 VatAmount 是有问题的值。 Excel文件是否已预格式化(模板等?)在此格式化数字时,不会更改工作表本身的格式。
您需要提前或以编程方式更改工作表上显示的格式小数位数。