如何解决如何在 EmEditor 中添加?
我在 csv 文件中有以下数据。
vertical,7 day,email,fname,lname
Auto Finance,550418,531194,493993
Auto Finance,104890,101398,94135
Auto Finance,47684,45724,42696
Auto Finance,31939,30987,29514
我希望在一行中包含所有这些行的总和,如下所示:
vertical,1150418,950418,831194,793993
我该怎么做?
解决方法
您可以运行以下宏。必须在 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,y );
document.selection.Text = sum[x];
}
document.selection.NewLine();
}
要运行此代码,请将此代码保存为例如 SumCSV.jsee
,然后从 宏 菜单中的 选择... 中选择此文件。最后,在宏菜单中选择运行 SumCSV.jsee。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。