-3

我在 csv 文件中有以下数据。

vertical,7 day,email,fname,lname
Auto Finance,550418,550418,531194,493993
Auto Finance,104890,104890,101398,94135
Auto Finance,47684,47684,45724,42696
Auto Finance,31939,31939,30987,29514

我想要所有这些行的总和,如下所示:

vertical,7 day,email,fname,lname
Auto Finance,1150418,950418,831194,793993

我该怎么办?

4

1 回答 1

0

您可以运行以下宏。必须在 EmEditor 中以单元格选择模式打开 CSV 文件,并且在运行此宏之前选择所有数字单元格。

// write sums of each column below selected cells.
if( document.CellMode ) {
    x1 = document.selection.GetTopPointX( eePosCell );
    y1 = document.selection.GetTopPointY( eePosCell );
    x2 = document.selection.GetBottomPointX( eePosCell );
    y2 = document.selection.GetBottomPointY( eePosCell );
    
    var sum = [];
    for( var x = x1; x <= x2; ++x ) {
        sum[x] = 0;
    }
    
    for( var x = x1; x <= x2; ++x ) {
        for( var y = y1; y <= y2; ++y ) {
            var s = document.GetCell( y, x, eeCellIncludeNone );
            var n = parseInt( s );
            if( !isNaN( n ) ) {
                sum[x] += n;
            }
        }
    }
    
    document.selection.SetActivePoint( eePosCellLogical, x1, y2 );
    document.selection.LineOpen(false);
    y = y2 + 1;
    for( var x = x1; x <= x2; ++x ) {
        document.selection.SetActivePoint( eePosCellLogical, x, y );
        document.selection.Text = sum[x];
    }
    document.selection.NewLine();
}

要运行它,请将此代码另存为,例如,SumCSV.jsee然后从菜单中的选择...中选择此文件。最后,在Macros菜单中选择Run SumCSV.jsee 。

于 2021-07-14T18:02:14.630 回答