将 EmEditor 宏优化为 return Min/Max 大分隔数据的列长度

Optimised EmEditor Macro to return Min/Max column lengths on large delimited data

我目前有大型分隔数据集,我需要 return 每列的 min\max 长度。 我目前在 Emeditor v20.3 中使用以下代码,效果很好,但我想知道是否有更快的方法,特别是当有数百万行数据和数百列(并且此代码很慢)时。

任何可以包装到 javascript 宏中的更快的方法或想法将不胜感激。


for( col = colStart; col <= MaxCol; col++ ) {
    sTitle = document.GetCell( 1, col, eeCellIncludeNone );
    min = -1;
    max = 0;
    for( line = document.HeadingLines + 1; line < MaxLines; line++ ) {
        str = document.GetCell( line, col, eeCellIncludeQuotesAndDelimiter );
        if( min == -1 || min > str.length ) {
            min = str.length;
        }
        if( max < str.length ) {
            max = str.length;
        }
    }
    OutputBar.writeln( col + min + "    " + max + " " + sTitle);
}

请将 EmEditor 更新到 20.3.906 或更高版本,并且 运行 这个宏:

colStart = 1;
MaxCol = document.GetColumns();
document.selection.EndOfDocument();
yLastLine = document.selection.GetActivePointY( eePosCellLogical );

min = -1;
max = 0;
for( col = colStart; col <= MaxCol; col++ ) {
    sTitle = document.GetCell( 1, col, eeCellIncludeNone );
    document.selection.SetActivePoint( eePosCellLogical, col, 1 );
    
    editor.ExecuteCommandByID( 4064 );  // Find Empty or Shortest Cell
    y = document.selection.GetActivePointY( eePosCellLogical );
    if( y < yLastLine ) {  // check if not the last empty line
        str = document.GetCell( y, col, eeCellIncludeQuotes );
        min = str.length;
    }
    else {  // if the last empty line
        document.selection.SetActivePoint( eePosCellLogical, col, 1 );
        editor.ExecuteCommandByID( 4050 );  // Find Non-empty Shortest Cell
        y = document.selection.GetActivePointY( eePosCellLogical );
        str = document.GetCell( y, col, eeCellIncludeQuotes );
        min = str.length;
    }
    
    document.selection.SetActivePoint( eePosCellLogical, col, 1 );
    editor.ExecuteCommandByID( 4049 );  // Find Longest Cell
    y = document.selection.GetActivePointY( eePosCellLogical );
    str = document.GetCell( y, col, eeCellIncludeQuotes );
    max = str.length;
    OutputBar.writeln( col + " : " + min + "    " + max + " " + sTitle);
}