国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
刪除文本文件中相同的行

刪除文本文件中相同的行!
如果不使用數(shù)據(jù)庫,怎么樣才能刪除文本文件中相同的行呢?手工??。?0w行的記錄你試試手工????
下面這個(gè)腳本演示了如果刪除 文本文件中 相同的行!


Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H0001

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
Const ForReading = 1, ForWriting = 2, ForAppending = 8


strPathToTextFile = "D:\"
strFile = "done.txt"

objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPathtoTextFile & ";" & _
"Extended Properties=""text;HDR=NO;FMT=Delimited"""

objRecordSet.Open "Select DISTINCT * FROM " & strFile, _
objConnection, adOpenStatic, adLockOptimistic, adCmdText

Do Until objRecordSet.EOF
 str = objRecordSet.Fields.Item(0).Value
 Dim fso, f
 Set fso = CreateObject("Scripting.FileSystemObject")
 Set f = fso.OpenTextFile("D:\namelist.txt", ForAppending, True)
 f.WriteLine str
 f.Close

objRecordSet.MoveNext
Loop



D:\done.txt 是原始文件
D:\namelist.txt 是生成后的文件

 

 

把上面這些代碼,復(fù)制到一個(gè)txt文件中,修改成你所要的功能

另存為 *.vbs 后綴名就可以了!

 

===================================================

 

如何以A、B列為條件刪除相同行

我想設(shè)定用宏直接刪除相同行(比如:A1、B1與A4、B4數(shù)據(jù)相同則刪除A4、B4行),請(qǐng)大師們幫助一下。謝謝!


 

2006-11-13 16:29 HOmT398
參考
[CODE]
Sub test()
Dim mColl As New Collection
Dim iRow As Long, i As Long
Dim pt As Range
On Error Resume Next

With Sheet1
    iRow = .[a65536].End(xlUp).Row
    For i = 3 To iRow
    mColl.Add CStr(.Cells(i, 1) & .Cells(i, 2)), CStr(.Cells(i, 1) & .Cells(i, 2))
    If Err.Number <> 0 Then
        If pt Is Nothing Then
            Set pt = .Cells(i, 1)
        Else
            Set pt = Union(pt, .Cells(i, 1))
        End If
        Err.Clear
    End If
    Next
End With
pt.EntireRow.Select
End Sub
[/CODE]


 

2006-11-13 16:30 HOmT398
替換空格一類的自己做 :P

如果數(shù)據(jù)很多的話加一句:
application.ScreenUpdating=False

[[i] 本帖最后由 HOmT398 于 2006-11-13 16:31 編輯 [/i]]


 

2006-11-13 17:37 yky888
版主的方法很好!
進(jìn)一步請(qǐng)教:我需要把d列的數(shù)據(jù)也加為條件,您的代碼可作怎樣的變通呢?
請(qǐng)看我的附件。謝謝!


 

2006-11-13 17:43 HOmT398
[quote]原帖由 [i]yky888[/i] 于 2006-11-13 17:37 發(fā)表
版主的方法很好!
進(jìn)一步請(qǐng)教:我需要把d列的數(shù)據(jù)也加為條件,您的代碼可作怎樣的變通呢?
請(qǐng)看我的附件。謝謝! [/quote]

參考
[code]
Sub test()
Dim mColl As New Collection
Dim iRow As Long, i As Long
Dim pt As Range
Dim strKey As String
On Error Resume Next
With Sheet1
    iRow = .[a65536].End(xlUp).Row
    For i = 3 To iRow
    strKey = CStr(.Cells(i, 1) & .Cells(i, 2) & .Cells(i, 4))
    mColl.Add strKey, strKey
    If Err.Number <> 0 Then
        If pt Is Nothing Then
            Set pt = .Cells(i, 1)
        Else
            Set pt = Union(pt, .Cells(i, 1))
        End If
        Err.Clear
    End If
    Next
End With
pt.EntireRow.Select
End Sub
[/code]


 

2006-11-13 17:45 HOmT398
回復(fù) #4 yky888 的帖子

再改一改
[code]Sub test()
Dim mColl As New Collection
Dim iRow As Long, i As Long
Dim pt As Range
Dim strKey As String

On Error Resume Next
Application.ScreenUpdating = False
With Sheet1
    iRow = .[a65536].End(xlUp).Row
    For i = 3 To iRow
        strKey = CStr(.Cells(i, 1) & .Cells(i, 2) & .Cells(i, 4))
        If Len(strKey) > 0 Then
            mColl.Add strKey, strKey
            If Err.Number <> 0 Then
                If pt Is Nothing Then
                    Set pt = .Cells(i, 1)
                Else
                    Set pt = Union(pt, .Cells(i, 1))
                End If
                Err.Clear
            End If
        End If
    Next
End With
Application.ScreenUpdating=True
pt.EntireRow.Select
End Sub[/code]

===============================================

假設(shè)源文件叫dup.txt,用以下命令行生成過濾后的unique.txt:

copy /y nul unique.txt && for /f "delims=" %a in (dup.txt) do @(findstr /b /e /c:"%a" unique.txt >nul || echo.%a>>unique.txt)

效率不高,如果數(shù)據(jù)量特別大的話,慎用。

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
搜集各種Excel VBA的命令供參考!
【20190129】- 在Excel名冊(cè)中自動(dòng)批量插入照片
Excel | VBA輕松實(shí)現(xiàn)跨多工作表查詢數(shù)據(jù)
ASP導(dǎo)出EXCEL通用
Excel中字典應(yīng)用綜合示例
EXCEL中VBA基礎(chǔ)應(yīng)用
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服