我在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
我该怎么做?
您可以运行以下宏。CSV文件必须在EmEditor的"单元格选择"模式下打开,并且在运行此宏之前选择所有数字单元格。
// 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
,然后从"选择…"中选择此文件在宏菜单中。最后,在宏菜单中选择运行SumCSV.jsee。