0

我目前有大型分隔数据集,我需要返回每列的最小\最大长度。我目前在 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);
}
4

1 回答 1

1

请将 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);
}
于 2020-12-09T21:50:07.580 回答