2

我正在寻找一种像在 Excel 中一样查看 CSV 文件的方法(布局清晰) Excel 的唯一问题是它不会通知您更新,也不会在文件“打开”后关闭文件,这与 Notepad++ 不同允许您查看文件何时更新,它还允许您打开文件然后在 python 中操作它...

Notepad++ 的唯一问题是无法轻松读取 CSV。

记事本++

  • 优点
    • “此文件已被其他程序修改,要重新加载吗?”
    • 以可视方式加载数据后关闭文件。
    • 可以轻松地与其他文件进行比较。
  • 缺点
    • 没有清晰的视觉观察者。

Excel

  • 优点
    • 清晰的视觉查看器。
  • 缺点
    • 视觉加载数据后不会关闭文件。
    • 当文件被另一个程序修改时不会提醒您(如果它在 Excel 中打开,则无法修改)
    • 无法轻松与另一个文件进行比较。

有人知道可以帮助我的程序吗?

data,data,datalongdatadatalongdata,datalongdata,datalongdata,data,data,data,datalongdata,data,data,data,data,datalongdata,datalongdata,data
data,data,data,data,data,data,data,data,data,data,data,data,data,data,data,data
data,data,data,data,data,data,data,data,data,data,data,data,data,data,data,data
data,data,data,data,data,data,data,data,data,data,data,data,data,data,datalongdatadatalongdatadatalongdatadatalongdatadatalongdata,data
data,data,data,data,data,data,data,data,data'data,data,data,data,data,data,data,data
data,data,data,data,data,data,data,data,data,data,data,data,data,data,data,data
data,data,data,data,data,data,data,data,data,data,data,data,data,data,data,data
data,data,data,data,data,data,data,data,data,data,data,data,data,datalongdatadatalongdatadatalongdatadatalongdata,data,data

之后(查看第 5 行data'data

data,data,datalongdatadatalongdata,datalongdata,datalongdata,data,data,data,datalongdata,data,data,data,data,datalongdata,datalongdata                                                ,data
data,data,data                    ,data        ,data        ,data,data,data,data        ,data,data,data,data,data        ,data                                                        ,data
data,data,data                    ,data        ,data        ,data,data,data,data        ,data,data,data,data,data        ,data                                                        ,data
data,data,data                    ,data        ,data        ,data,data,data,data        ,data,data,data,data,data        ,datalongdatadatalongdatadatalongdatadatalongdatadatalongdata,data
data,data,data                    ,data        ,data        ,data,data,data,data'data,data,data,data,data,data,data,data
data,data,data                    ,data        ,data        ,data,data,data,data,data,data,data,data,data,data,data
data,data,data                    ,data        ,data        ,data,data,data,data,data,data,data,data,data,data,data
data,data,data                    ,data        ,data        ,data,data,data,data,data,data,data,data,datalongdatadatalongdatadatalongdatadatalongdata,data,data
4

2 回答 2

5

您将永远无法在 Notepad++ 中获得出色的 Excel 视觉体验!

我所知道的唯一“解决方案”位于 TextFX 插件中。

选择所有文本,然后转到TextFX > TextFX Edit > Line up multiple lines by (,)。这将转换以下示例:

heeey,this,is,a,testtttttttttt
34,3,2234,3,5
123,123,123,123,123

至:

heeey,this,is  ,a  ,testtttttttttt
34   ,3   ,2234,3  ,5
123  ,123 ,123 ,123,123

PS。您可能需要检查CSVed。从来没有使用过它,所以我不知道它是否具有您需要的所有功能,但从屏幕截图看起来不错:)

于 2013-11-11T14:44:35.387 回答
1

我回来了一个新的答案:) 在你发现这个错误之后TextFX,我决定使用Python Script插件创建更好的东西。

例子

它将转换以下示例:

heeey,this,is,a,testtttttttttt
34,3
123,123,123,123,123

至:

+ ----------------------------------------- +
| heeey | this | is  | a   | testtttttttttt |
| 34    | 3    |     |     |                |
| 123   | 123  | 123 | 123 | 123            |
+ ----------------------------------------- +

以及以下内容:

title1,title2,title3,title4,title5,title6,title7,title8,title9
datalongdata,datalongdata,data,data,data,datalongdata,data,data,data
data,data,data,data,data,data,data,datalongdatadatalongdatadatalongdatadatalongdatadatalongdata,data
data,data'data,data,data,data,data,data,data,data

至:

+ ------------------------------------------------------------------------------------------------------------------------------------------------------ +
| title1       | title2       | title3 | title4 | title5 | title6       | title7 | title8                                                       | title9 |
+ ------------------------------------------------------------------------------------------------------------------------------------------------------ +
| datalongdata | datalongdata | data   | data   | data   | datalongdata | data   | data                                                         | data   |
| data         | data         | data   | data   | data   | data         | data   | datalongdatadatalongdatadatalongdatadatalongdatadatalongdata | data   |
| data         | data'data    | data   | data   | data   | data         | data   | data                                                         | data   |
+ ------------------------------------------------------------------------------------------------------------------------------------------------------ +

安装

  1. 从官方网站或从官方网站安装Python Script插件。Plugin Manager
  2. 安装后,转到Plugins > Python Script > New Script. 为您的新文件选择一个文件名(例如pretty_csv.py)并复制下面的代码。
  3. 打开您的 csv 文件,然后运行Plugins > Python Script > Scripts > pretty_csv.py​​. 这将在您的表格中打开一个新选项卡。

请注意,在脚本的前几行中,您可以更改一些参数。我希望变量名称是不言自明的!我想最重要的是布尔值,borderheader.

#define parameters
delimiter=","
new_delimiter=" | "
border=True
border_vertical_left="| "
border_vertical_right=" |"
border_horizontal="-"
border_corner_tl="+ "
border_corner_tr=" +"
border_corner_bl="+ "
border_corner_br=" +"
header=True
border_header_separator="-"
border_header_left="+ "
border_header_right=" +"
newline="\n"

#load csv
content=editor.getText()
content=content.rstrip(newline)
rows=content.split(newline)

#find the max number of columns (so having rows with different number of columns is no problem)
max_columns=max([row.count(delimiter) for row in rows])
if max_columns>0:
    max_columns=max_columns+1

    #find the max width of each column
    column_max_width=[0]*max_columns
    for row in rows:
        for index,column in enumerate(row.split(delimiter)):
            width=len(column)
            if width>column_max_width[index]:
                column_max_width[index]=width
    total_length=sum(column_max_width)+len(new_delimiter)*(max_columns-1)

    #create new document
    notepad.new()

    #apply the changes
    left=border_vertical_left if border is True else ""
    right=border_vertical_right if border is True else ""
    left_header=border_header_left if border is True else ""
    right_header=border_header_right if border is True else ""
    for row_number,row in enumerate(rows):
        columns=row.split(delimiter)
        max_index=len(columns)-1
        for index in range(max_columns):
            if index>max_index:
                columns.append(' ' * column_max_width[index])
            else:
                diff=column_max_width[index]-len(columns[index])
                columns[index]=columns[index] + ' ' * diff

        if row_number==0 and border is True: #draw top border
            editor.addText(border_corner_tl + border_horizontal * total_length + border_corner_tr + newline)
        editor.addText(left + new_delimiter.join(columns) + right + newline) #print the new row
        if row_number==0 and header is True: #draw header's separator
            editor.addText(left_header + border_header_separator * total_length + right_header + newline)
        if row_number==len(rows)-1 and border is True: #draw bottom border
            editor.addText(border_corner_bl + border_horizontal * total_length + border_corner_br)
else:
    console.clear()
    console.show()
    console.writeError("No \"%s\" delimiter found!" % delimiter)

如果您发现任何错误或有任何建议,请告诉我!

于 2013-11-13T21:38:47.747 回答