半成品

Sub readCsv()
    Dim filePath  As String
    filePath = Sheet1.Cells(2, 3).Value
    'MsgBox (filePath)
    Sheet2.Rows().Clear
   
    Dim TextLine
    Dim rowLine As Integer
    Dim lineArray() As String
       
    changeRow = False
    rowLine = 1
    Dim startNewLineFlg As Boolean
    Dim endNewLineFlg As Boolean
    Dim lineArr() As String
    Dim columnArr() As String
    Dim columnNum As Integer
    'MsgBox (TextGetByFile(filePath))
   
    lineArr = Split(TextGetByFile(filePath), Chr(34) & vbCrLf)
   
    For i = 1 To UBound(lineArr)
        columnArr = Split(lineArr(i), ",")
        For j = 1 To UBound(columnArr)
            Sheet2.Cells(i, j).Value = Mid(columnArr(j - 1), 2, Len(columnArr(j - 1)) - 2)
        Next
    Next
End Sub
Sub makeCsv()
Dim filePath  As String
    filePath = Sheet1.Cells(4, 3).Value
    cl = Sheet2.Range("AV" & Sheet2.UsedRange.Row).End(xlToLeft).Column
    rw = Sheet2.Cells(65536, Sheet2.UsedRange.Column).End(xlUp).Row
    Dim allStr As String
    Dim lineStr As String
    lineStr = ""
    allStr = ""
   
    For i = 1 To rw
        For j = 1 To cl
            If lineStr = "" Then
                lineStr = """" & Sheet2.Cells(i, j).Value & """"
            Else
                lineStr = lineStr & ",""" & Sheet2.Cells(i, j).Value & """"
            End If
               
        Next
       
        If allStr = "" Then
            allStr = lineStr
        Else
            allStr = allStr & Chr(34) & vbCrLf & lineStr
        End If
        lineStr = ""
    Next
   
    MsgBox (allStr)
   
    Open filePath For Output As #1
    Print #1, allStr
    Close #1
   
End Sub

Private Sub WriteOut(strPath As String, str As String)
    If Not Dir(strPath, vbDirectory) = vbNullString Then
        Kill (strPath)
    End If
   
    Dim ibufsize As Long
    Dim irst
End Sub

Public Function TextGetByFile(ByVal pFileName As String) As String
    Dim tOutText     As String
    Dim tBytes()     As Byte
    tBytes() = BytesGetByFile(pFileName)
    tOutText = StrConv(tBytes(), vbUnicode)
    TextGetByFile = tOutText
End Function

Public Sub TextPutToFile(ByVal pFileName As String, ByRef pText As String, Optional ByVal pFillFile As Boolean = False)
    Dim tBytes()     As Byte
    tBytes() = StrConv(pText, vbFromUnicode)
    BytesPutToFile pFileName, pBytes(), pFillFile
End Sub

Public Function BytesGetByFile(ByVal pFileName As String) As Byte()
    Dim tOutBytes()     As Byte
    Dim tOutBytes_Length     As Long
    Dim tFileNumber     As Integer
    tFileNumber = FreeFile
    Open pFileName For Binary As #tFileNumber
        Dim tFileSize     As Long
        tFileSize = LOF(tFileNumber)
        tOutBytes_Length = tFileSize - 1
        ReDim tOutBytes(tOutBytes_Length)
        Get tFileNumber, 1, tOutBytes()
    Close #tFileNumber
    BytesGetByFile = tOutBytes()
End Function

Public Sub BytesPutToFile(ByVal pFileName As String, ByRef pBytes() As Byte, Optional ByVal pFillFile As Boolean = False)
    Dim tFileNumber     As Integer
    tFileNumber = FreeFile
    If pFillFile Then
        Open pFileName For Output As #tFileNumber
        Close #tFileNumber
    End If
    tFileNumber = FreeFile
    Open pFileName For Binary As #tFileNumber
        Put tFileNumber, 1, pBytes()
    Close #tFileNumber
End Sub

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值