您好,我有一組列,其中按行顯示多個產品的資料。我需要透過建立具有產品名稱後綴的新的相同列來拆分此數據,並僅複製前一列中的匹配產品數據。我只需要幫助來複製適當的數據。我試圖透過選擇和複製貼上來做到這一點,但我不知道該怎麼做。感興趣的區域從 dt << 選擇位置開始。
Names Default To Here( 1 );
dt = Current Data Table();
colNames = dt << Get Column Names(String);
//Select set of columns to split
for (i = nitems(colNames), i > 0, i--,
if (!contains(colNames[i], "SPC"),
remove from(colNames, i);
);
);
//Add new columns with product name suffix and copy/paste properties
Summarize(unique_values=by(:Products));
colNames2=colNames;
for (k = nitems(unique_values), k > 0, k--,
for (i = nitems(colNames), i > 0, i--,
colNames2[i] = colNames[i] || " " || unique_values[k];
dt << New Column( colNames2[i] );
);
for( j = 1, j <= nitems(colNames), j++,
colProps = Column( dt, colNames[j] ) << Get Column Properties;
Column( dt, colNames2[j] ) << Add Column Properties( colProps );
);
<U><STRONG> dt << Select Where( :Products == unique_values[k] );
dt << selectColumns(colNames);
dt << Copy;
dt << selectColumns(colNames2);
dt << Paste;</STRONG></U>
);
你好,如果你想根據行選擇複製和粘貼值,你可以編寫如下代碼。
我希望它有所幫助。
dt << Select Where( :Products == unique_values[k] );
r = dt << Get Selected Rows();
val = As Column( colNames[i] )[r];
For( h = 1, h <= N Row( val ), h++,
As Column( colNames2[i] )[r[h]] = val[h]
);