如下图“前面”所示,用逗号分隔的每一列都不对齐。是否有任何方法像Excel中的显示效果那样垂直对齐每一列?
我希望的效果显示在图片“之后”。
感谢@Martin,我可以像图片"Method_1“一样对齐文件。正如他所提到的,有些字符仍然不能很好地对齐。我想知道这种方法能不能得到改进?
发布于 2017-11-02 10:51:29
您可以使用TextFX插件:编辑>排列多行通过.
注意:如果文件是只读的,这是不起作用的。
http://tomaslind.net/2016/02/18/how-to-align-columns-in-notepad/
更新2019年:从SourceForge下载链接
发布于 2021-10-26 14:02:45
也许不是您想要的,但我最近在Notepad++中添加了一个Notepad++,它还为csv和固定宽度的数据文件添加了语法高亮显示,这意味着每一列都有不同的颜色,因此更容易看到。
发布于 2018-11-28 23:47:25
您可以使用这个python插件脚本,它利用csv库来处理引用的csv和许多其他变体。
设置:
CSVtoTable.py
import csv
inputlines = editor.getText().split('\n')
# Get rid of empty lines
inputlines = [line.strip() for line in inputlines if line.strip()]
reader = csv.reader(inputlines, delimiter=',')
csvlist = [line for line in reader]
# transpose to calculate the column widths and create a format string which left aligns each row
t_csvlist = zip(*csvlist)
col_widths = [max([len(x) for x in t_csvlist[y]]) for y in range(len(t_csvlist))]
# To right align - change < to >
fmt_str = ' '.join(['{{:<{0}}}'.format(x) for x in col_widths]) + '\r\n'
text = []
for line in csvlist:
text.append(fmt_str.format(*line))
# open a new document and put the results in there.
notepad.new()
editor.addText(''.join(text))
更新(右对齐数字和左对齐字符串):
如果您想从CSV中正确对齐数字字段,请使用下面的python脚本--它将查看csv的第二行以确定字段的类型。
import csv
import re
num_re = re.compile('[-\+]?\d+(\.\d+)?')
inputlines = editor.getText().split('\n')
# Get rid of empty lines
inputlines = [line.strip() for line in inputlines if line.strip()]
reader = csv.reader(inputlines, delimiter=',')
csvlist = [line for line in reader]
# Transpose to calculate the column widths and create a format string which left aligns each row
t_csvlist = zip(*csvlist)
col_widths = [max([len(x) for x in t_csvlist[y]]) for y in range(len(t_csvlist))]
# Numbers get right aligned
type_eval_line = csvlist[1 if len(csvlist)>1 else 0]
alignment = ['>' if num_re.match(item) else '<' for item in type_eval_line]
# Compute the format string
fmt_str = ' '.join(['{{:{0}{1}}}'.format(a,x) for x,a in zip(col_widths,alignment)]) + '\r\n'
text = []
for line in csvlist:
text.append(fmt_str.format(*line))
# open a new document and put the results in there.
notepad.new()
editor.addText(''.join(text))
https://stackoverflow.com/questions/45165105
复制相似问题