VB6导出为CSV:如何保留零值

时间:2016-03-28 02:24:41

标签: csv vb6 export-to-csv

如何在导出csv文件时保留零值,如果在记事本上打开它可以正常工作,但在excel中它会删除零。有没有办法可以将数字转换为代码中的文本?例如。 ' 4.1200' = 4.12

 Private Sub ExportToCSV()
  Me.progCashr.Value = 25
Static iNum
Dim iRow, iCol As Integer
Dim sText As String
Dim sPath As String
iNum = FreeFile()
Me.progCashr.Value = 50
With cd
    On Error GoTo errtrap
    .CancelError = True
    .Filter = "*.CSV|*.CSV"
    .ShowSave
    If FileExists(.FileName) Then
        If fMessageBox("", "Overwrite File?", "Yes", "No", 0, 1, True) = 1 Then
        Me.progCashr.Value = 100
            Open .FileName For Output As #iNum
            MsgBox ("Export Success!")
        Else
            Exit Sub
        End If
    Else
        Open .FileName For Output As #iNum

    End If

End With

With Grid1
    For iRow = 2 To .Rows - 1
        sText = ""
        For iCol = 1 To .Cols - 1
            sText = sText & Replace(.Cell(iRow, iCol).Text, ",", "") & ","
        Next iCol
        If sText <> "" Then
            sText = Left$(sText, Len(sText) - 1)
            Print #iNum, sText
        End If
    Next iRow

End With
MsgBox ("Export Success!")
Close #iNum
Exit Sub
End Sub

0 个答案:

没有答案