将 Excel 中的信息合并到 Notepad++

Merge information from Excel to Notepad++

我有点问题。虽然我目前使用的技术在某种程度上是可行的,但它肯定不是最快或最简单的做事方式。我附上了 excel 文件的图片,下面是所需的结果。

场景:

我有一个包含多个产品的 excel 文件。假设产品名称 HX44 可以容纳 100,000 辆车,在 Excel 文件中,A 列是所有兼容的车辆,而 2 列是每辆车重复相同的产品名称。我正在尝试合并该指定产品的所有 A 列,因此它全部在一行上,而不是多行。

尝试了繁琐的解决方案:

Excel 通过每个单元格仅允许 8000 个字符来限制这一点,所以我所做的是通过产品在 Excel 中过滤,然后将车辆列表复制到 NotePad++,然后突出显示复制的文本,并选择 "remove unnecessary blank and EOL",然后将所有信息连接到 1 行。然后我可以将我的单元格从 B2-> 复制到 Notepad++ 中,在下面给出生成的结果(如果你将它复制到 Notepad++ 或记事本中,它会出现在一行中。

我遇到的难题是我有几百万行 excel 文件,我想知道是否有办法以更快的方式完成此操作,即是否有迁移此信息的工具从 Excel 到 Notepad++?

预期结果:

Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|240D|2.4L DIESEL|1983|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|300CD|3.0L DIESEL|1983|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|300D|3.0L DIESEL|1983|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|300TD|3.0L DIESEL|1983|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|240D|2.4L DIESEL|1982|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|300D|3.0L DIESEL|1982|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|300TD|3.0L DIESEL|1982|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|240D|2.4L DIESEL|1981|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|300CD|3.0L DIESEL|1981|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|300D|3.0L DIESEL|1981|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|300TD|3.0L DIESEL|1981|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|240D|2.4L DIESEL|1980|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|300CD|3.0L DIESEL|1980|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|300D|3.0L DIESEL|1980|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|240D|2.4L DIESEL|1979|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|240D|2.4L DIESEL|1978|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|240D|2.4L DIESEL|1977|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|300D|3.0L DIESEL|1977|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|280|2.8L |1976|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|280C|2.8L |1976|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|280S|2.8L |1976|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|280|2.8L |1975|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|280C|2.8L |1975|| Root|Home|PRODUCTS|Filtration|MERCEDES-BENZ|280S|2.8L |1975||;Oil Filter HX 45•;HX 45•;As a leading global development partner for the automotive and engine industry, MAHLE offers unique systems competence in the areas of engine systems, filtration, electrics/mechatronics, and thermal management. The MAHLE Group ranks among the top three systems suppliers worldwide for mobile applications in these sectors.In the original equipment industry, MAHLE provides technologically innovative solutions for automotive, commercial vehicle, machinery, and other industrial applications. The Aftermarket business unit also serves the independent parts market with MAHLE products in OE quality.>MAHLE has a local presence in all major world markets. In 2014, some 66,000 employees at approximately 150 production locations are expected to generate sales of around EUR ten billion. At ten major research and development centers in Germany, Great Britain, the USA, Brazil, Japan, China, and India, more than 4,500 development engineers and technicians are working on forward-looking concepts, products, and systems.;10;10;

Excel file example

您可以将 excel 文件保存为 CSV (Comma delimited)Text (Tab delimited)。然后将整个文件保存为易于在 Notepad++ 或其他基于文本的工具中使用的格式。 Excel 可以在修改后打开任一类型的文件。

您说您希望它们全部在一行中,但您的预期结果将它们显示在不同的行中。我假设您希望将它们全部放在一条线上。

Sub MakeTextFile()

    Dim vaData As Variant
    Dim i As Long
    Dim aCar() As String, lCarCnt As Long
    Dim aLine() As String, lLineCnt As Long
    Dim sPart As String
    Dim sFile As String, lFile As String

    'Read in all the data
    vaData = Sheet1.Range("A1").CurrentRegion.Value

    'Establish the first part
    sPart = vaData(1, 3)
    For i = LBound(vaData, 1) To UBound(vaData, 1)
        'if it's a new part make a line for the text file
        If vaData(i, 3) <> sPart Then AddToLine aLine, lLineCnt, lCarCnt, sPart, vaData, aCar, i

        'add the current car to the car array
        lCarCnt = lCarCnt + 1
        ReDim Preserve aCar(1 To lCarCnt)
        aCar(lCarCnt) = vaData(i, 1)

    Next i

    'the last line won't be a change in part, so add the line here
    AddToLine aLine, lLineCnt, lCarCnt, sPart, vaData, aCar, i - 1

    'write the lines to a file
    sFile = ThisWorkbook.Path & Application.PathSeparator & "PartsCars.txt"
    lFile = FreeFile
    Open sFile For Output As lFile
    Print #lFile, Join(aLine, vbNewLine)
    Close lFile

End Sub

Public Sub AddToLine(ByRef aLine() As String, ByRef lLineCnt As Long, ByRef lCarCnt As Long, ByRef sPart As String, ByRef vaData As Variant, ByRef aCar() As String, ByVal i As Long)

    'write all the cars plus selected info (cols 2, 3, 4) to the line
    lLineCnt = lLineCnt + 1
    ReDim Preserve aLine(1 To lLineCnt)
    aLine(lLineCnt) = Join(aCar, vbNullString) & vaData(i - 1, 2) & vaData(i - 1, 3) & vaData(i - 1, 4)
    ReDim aCar(1 To 1) 'reinitialize Car array
    lCarCnt = 0
    sPart = vaData(i, 3) 'set the new part

End Sub