Excel:单列数据到多行

发布于 2025-02-12 18:37:04 字数 1447 浏览 0 评论 0原文

我有以下内容将行复制成多行,其中字段与逗号分开。

scriptnm表名称
scripta.kshdb.table1,db.table2
scripta.expdb.table4

to替换如下:

scriptnmtable name
scripta.kshdb.table2
scripta.kshdb.table2
scripta.expdb.table4

我可以尝试将行分开使用逗号定界符的列,但以下行不应影响。

更新的重复输入:

scriptnm表名称
scripta.ksh
scriptb.kshdb.table2
scriptc.expdb.table3
scriptd.expd.expdb.table4,db.table5
scripte.exp scripte.exp < /代码>
scriptf.expdb.table9
scriptg.expdb.table10,db.table11,db.table13
scripth.exp.expdb.table20,db。 table21,db.table23,db.table34

I have a below thing to replicate the rows into multiple rows where the fields are separated with comma.

SCRIPTNMTABLE NAME
scriptA.kshDB.TABLE1, DB.TABLE2
scriptA.expDB.TABLE4

to replace as below:

SCRIPTNMTABLE NAME
scriptA.kshDB.TABLE2
scriptA.kshDB.TABLE2
scriptA.expDB.TABLE4

I can try to split the rows to columns using comma delimiter, but the below rows should not effect.

Updated relistic input:

SCRIPTNMTABLE NAME
scriptA.ksh
scriptB.kshDB.TABLE2
scriptC.expDB.TABLE3
scriptD.expDB.TABLE4,DB.TABLE5
scriptE.exp
scriptF.expDB.TABLE9
scriptG.expDB.TABLE10,DB.TABLE11,DB.TABLE13
scriptH.expDB.TABLE20,DB.TABLE21,DB.TABLE23,DB.TABLE34

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

听不够的曲调 2025-02-19 18:37:04

基于公式的excel 2010的解决方案,标签:

假设:

  1. a1中的数据:b3(第1行中的标题)
  2. 范围b2:b2:b3

>在f2

这个数组公式= if(rows(b $ 2:b2)&gt; sum(1+len(b $ 2:b $ 3)-len(替代(b $ 2:b $ 3,“,”,“,”,“”)),“” ,索引($ 2:A $ 3,IFERROR(1+匹配(行)(b $ 2 :b2)-1/2,mmult(n(b $ 2:b $ 3)&gt; = transpose(row(b $ 2:b $ 3))),1+len(b $ 2:b $ 3) - len(替代) (b $ 2:b $ 3,“,”,“”))),1)))

复制直到开始获取结果的空白。

f2中的非阵列公式:

= if(f2 =““”,“”,TRIM(MID(index(index(b $ 2:B $ 3)) $ 3,0)),“,”,rept(“”,99),99*(countif(f $ 2:f2,f2)-1)-1)+1,99))))

已复制根据需要。

Formula-based solution for Excel 2010, as tagged:

Assuming:

  1. Data in A1:B3 (with headers in row 1)
  2. The range B2:B3 does not contain any empty cells

This array formula in F2:

=IF(ROWS(B$2:B2)>SUM(1+LEN(B$2:B$3)-LEN(SUBSTITUTE(B$2:B$3,",",""))),"",INDEX(A$2:A$3,IFERROR(1+MATCH(ROWS(B$2:B2)-1/2,MMULT(N(ROW(B$2:B$3)>=TRANSPOSE(ROW(B$2:B$3))),1+LEN(B$2:B$3)-LEN(SUBSTITUTE(B$2:B$3,",","")))),1)))

Copy down until you start to get blanks for the results.

Non-array formula in F2:

=IF(F2="","",TRIM(MID(SUBSTITUTE(INDEX(B$2:B$3,MATCH(F2,A$2:A$3,0)),",",REPT(" ",99)),99*(COUNTIF(F$2:F2,F2)-1)+1,99)))

Copied down as required.

流云如水 2025-02-19 18:37:04

您可以使用电源查询在Windows Excel 2010+和Office 365 Excel中获得所需的输出,然后

  • 在您的原始表中选择一些单元格
  • data =&gt;获取&amp; transform =&gt;从表/范围从表格中
  • 从PQ UI打开时,导航到home =&gt;高级编辑器
  • 在代码的第2行中记下表名。
  • 在下面的 m-code 上替换现有代码
  • 将粘贴代码的第2行中的表名更改为“真实”表名称,
  • 请检查任何注释,还将应用步骤窗口,更好地了解算法和步骤

m代码

let

//change next line to reflect the actual table name in your workbook
    Source = Excel.CurrentWorkbook(){[Name="Table9"]}[Content],

//set data type to text
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"SCRIPTNM", type text}, {"TABLE NAME", type text}}),

//remove the empty "TABLE NAME" rows
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([TABLE NAME] <> null)),

//Split TABLE NAME column by the comma into rows
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Filtered Rows", {{"TABLE NAME", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "TABLE NAME")
in
    #"Split Column by Delimiter"

”

You can obtain your desired output using Power Query, available in Windows Excel 2010+ and Office 365 Excel

  • Select some cell in your original table
  • Data => Get&Transform => From Table/Range or From within sheet
  • When the PQ UI opens, navigate to Home => Advanced Editor
  • Make note of the Table Name in Line 2 of the code.
  • Replace the existing code with the M-Code below
  • Change the table name in line 2 of the pasted code to your "real" table name
  • Examine any comments, and also the Applied Steps window, to better understand the algorithm and steps

M Code

let

//change next line to reflect the actual table name in your workbook
    Source = Excel.CurrentWorkbook(){[Name="Table9"]}[Content],

//set data type to text
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"SCRIPTNM", type text}, {"TABLE NAME", type text}}),

//remove the empty "TABLE NAME" rows
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([TABLE NAME] <> null)),

//Split TABLE NAME column by the comma into rows
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Filtered Rows", {{"TABLE NAME", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "TABLE NAME")
in
    #"Split Column by Delimiter"

enter image description here

穿透光 2025-02-19 18:37:04

基于公式的替代解决方案,(阵列公式需要用ctrl+shift+Entry+Enter

“

•单元格中使用的公式d2 - &gt;要获取 scriptnm

=IFERROR(IF(ROW(A1)=1,A2,
IF(COUNTIF($D$1:D1,D1)+1>SUMPRODUCT((MID(
VLOOKUP(D1,$A$2:$B$3,2,),ROW($1:$104),1)=",")*1)+1,
INDEX($A$2:$A$3,MATCH(D1,$A$2:$A$3,)+1),D1))&"","")

•单元格中使用的公式e2 - &gt;要获取表名

=IFERROR(TRIM(MID(SUBSTITUTE(
VLOOKUP(D2,$A$2:$B$3,2,),",",REPT(" ",100)),
(COUNTIF($D$1:D2,D2)-1)*100+1,100)),"")

或另一种方式,

g2中使用的公式 - &gt;要获取 scriptnm

=IFERROR(INDEX($A$2:$A$3,MATCH(TRUE,COUNTIF(G$1:G1,$A$2:$A$3)<
(LEN($B$2:$B$3)-LEN(SUBSTITUTE($B$2:$B$3,",",""))+1),0)),"")

•单元格中使用的公式h2 - &gt;获取表名

=IFERROR(TRIM(MID(SUBSTITUTE(
VLOOKUP(G2,$A$2:$B$3,2,0)&", ",", ",REPT(" ",100)),
COUNTIF($G$2:G2,G2)*100-99,100)),"")

Formula based alternative solutions, (Array Formulas needs to be keyed with CTRL+SHIFT+ENTER)

FORMULA_SOLUTION

• Formula used in cell D2 --> To Get SCRIPTNM

=IFERROR(IF(ROW(A1)=1,A2,
IF(COUNTIF($D$1:D1,D1)+1>SUMPRODUCT((MID(
VLOOKUP(D1,$A$2:$B$3,2,),ROW($1:$104),1)=",")*1)+1,
INDEX($A$2:$A$3,MATCH(D1,$A$2:$A$3,)+1),D1))&"","")

• Formula used in cell E2 --> To Get TABLE NAME

=IFERROR(TRIM(MID(SUBSTITUTE(
VLOOKUP(D2,$A$2:$B$3,2,),",",REPT(" ",100)),
(COUNTIF($D$1:D2,D2)-1)*100+1,100)),"")

Or, One more way,

• Formula used in cell G2 --> To Get SCRIPTNM

=IFERROR(INDEX($A$2:$A$3,MATCH(TRUE,COUNTIF(G$1:G1,$A$2:$A$3)<
(LEN($B$2:$B$3)-LEN(SUBSTITUTE($B$2:$B$3,",",""))+1),0)),"")

• Formula used in cell H2 --> To Get TABLE NAME

=IFERROR(TRIM(MID(SUBSTITUTE(
VLOOKUP(G2,$A$2:$B$3,2,0)&", ",", ",REPT(" ",100)),
COUNTIF($G$2:G2,G2)*100-99,100)),"")

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文