I\'m looking for a way to view CSV files as you would in Excel (nice clear layout) the only issue with Excel is that it doesn\'t notify you of updates nor does it close the file
I'm back with a new answer :) After you found that bug in TextFX
, I decided to create something better using the Python Script
plugin.
It will convert the following example:
heeey,this,is,a,testtttttttttt
34,3
123,123,123,123,123
To:
+ ----------------------------------------- +
| heeey | this | is | a | testtttttttttt |
| 34 | 3 | | | |
| 123 | 123 | 123 | 123 | 123 |
+ ----------------------------------------- +
And the following:
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
To:
+ ------------------------------------------------------------------------------------------------------------------------------------------------------ +
| 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 |
+ ------------------------------------------------------------------------------------------------------------------------------------------------------ +
Python Script
plugin, from Plugin Manager
or from the official website.Plugins > Python Script > New Script
. Choose a filename for your new file (eg pretty_csv.py
) and copy the code that follows.Plugins > Python Script > Scripts > pretty_csv.py
. this will open a new tab with your table.Please note that in the first few lines of the script you can alter some parameters. I hope that the variables names are self-explanatory! I guess the most important ones are the boolean ones, border
and header
.
#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)
If you find any bugs or have any suggestions please let me know!
You will never achieve the great visual experience of Excel in Notepad++!
The only "solution" I know of, lie inside the TextFX plugin.
Select all your text, and then go to TextFX > TextFX Edit > Line up multiple lines by (,)
. This will convert the following example:
heeey,this,is,a,testtttttttttt
34,3,2234,3,5
123,123,123,123,123
To:
heeey,this,is ,a ,testtttttttttt
34 ,3 ,2234,3 ,5
123 ,123 ,123 ,123,123
PS. You might want to check CSVed. Never had to use it so I don't know if it has all the features you need, but from the screenshot it looks good :)