是否可以創建一個可在宏中使用的 javascript 函式,當按可變行移動資料列時,該函式可以按一定量移動資料。例如,通過將引數(iRow?)傳遞給 setcolumn 之類的東西,它會在上面插入資料(-1 丟失第一個值,然后插入,這就像將列資料向上移動一行)或 2 (將前 2 行列資料空白,然后粘貼其余資料,這就像將其向下移動 2 列?
在處理大量資料(數百萬行)時,對速度進行了理想優化。幾個例子。Col1 是源資料,Col2 正在復制該列并向上移動一行 (-1)。Col3 正在復制該初始 col 并向下移動兩個 ( 2):
| 資料 | 資料-1 | 資料 2 |
|---|---|---|
| 00000001 | 00000002 | |
| 00000002 | 00000003 | |
| 00000003 | 00000004 | 00000001 |
| 00000004 | 00000005 | 00000002 |
| 00000005 | 00000006 | 00000003 |
| 00000006 | 00000007 | 00000004 |
| 00000007 | 00000008 | 00000005 |
| 00000008 | 00000009 | 00000006 |
| 00000009 | 00000010 | 00000007 |
| 00000010 | 00000008 |
uj5u.com熱心網友回復:
我為 EmEditor宏撰寫了一個 JavaScript。MoveCells( -1, true )將選定的單元格向上復制,并將MoveCells( 1, false )選定的單元格向下移動。
// yShift : Specify how many rows to shift (move) the cell selection ( >0 : down, <0 : up )
function MoveCells( yShift, bCopy )
{
if( !yShift || yShift == 0 ) {
Quit();
}
if( !document.CellMode ) { // Must be cell selection mode
alert( "Cell selection mode must be turned on" );
Quit();
}
xTop = document.selection.GetTopPointX(eePosCellLogical);
yTop = document.selection.GetTopPointY(eePosCellLogical);
xBottom = document.selection.GetBottomPointX(eePosCellLogical);
yBottom = document.selection.GetBottomPointY(eePosCellLogical);
yLines = document.GetLines(); // retrieve the number of lines
if( document.GetLine( yLines ).length == 0 ) { // -1 if the last line is empty
--yLines;
}
if( yTop < 0 || xTop < 0 || xBottom < 0 || yBottom < 0 ) {
alert( "Incorrect selection" );
Quit();
}
if( xTop != xBottom ) {
alert( "More than one columns are selected" );
Quit();
}
bOldRedraw = Redraw;
Redraw = false;
bOldCombineHistory = CombineHistory;
CombineHistory = false;
yFirstLine = document.HeadingLines 1;
if( (yShift < 0 && yTop yShift < yFirstLine) || (yShift > 0 && yBottom yShift > yLines) ) {
if( yShift < 0 ) {
document.selection.SetActivePoint( eePosCellLogical, xTop, yFirstLine ); // move to the first line
nCount = yFirstLine - (yTop yShift);
for( i = 0; i < nCount; i ) {
document.selection.LineOpen(true);
}
yTop = nCount;
yBottom = nCount;
}
else {
document.selection.SetActivePoint( eePosCellLogical, xTop, yLines ); // move to the first line
nCount = yBottom yShift - yLines;
for( i = 0; i < nCount; i ) {
document.selection.LineOpen(false);
}
}
}
sDelimiter = document.Csv.Delimiter; // retrieve the delimiter
str = document.GetColumn( xTop, sDelimiter, eeCellIncludeQuotes, yTop, yBottom - yTop 1 ); // get cell selections from top to bottom, separated by delimiter
if( bCopy ) {
xTop
document.InsertColumn( xTop );
}
if( yShift > 0 ) { // shift down
for( i = 0; i < yShift; i ) { // insert delimiters before the copied string
str = sDelimiter str;
}
document.SetColumn( xTop, str, sDelimiter, eeDontQuote, yTop );
}
else { // shift up
for( i = 0; i < -yShift; i ) { // add delimiters to the copied string
str = sDelimiter;
}
document.SetColumn( xTop, str, sDelimiter, eeDontQuote, yTop yShift );
}
document.selection.SetActivePoint( eePosCellLogical, xTop, yTop yShift ); // move the current selection
document.selection.SetActivePoint( eePosCellLogical, xTop, yBottom yShift, true );
Redraw = bOldRedraw;
CombineHistory = bOldCombineHistory;
}
// Here is the main code
MoveCells( -1, true ); // Copy the selection up to right
MoveCells( 2, false ); // Move the selection down
要運行它,請將此代碼另存為,例如,Macro.jsee然后從宏選單中的選擇...中選擇此檔案。最后,在當前 CSV 檔案處于活動狀態時,在Macros選單中選擇Run Macro.jsee 。
參考:
- 宏:GetColumn 方法
- 宏:SetColumn 方法
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/484054.html
上一篇:分組后更新資料幀行的更快方法
下一篇:如何將numba用于以下代碼?
