This extensions allows you to edit csv files with an excel like table ui
If you don't have vs code to hand, you can use the online version at https://edit-csv.net
Execute the command edit as csv
to open an editor for the current file.
Execute the command again to switch back to the source file or to switch back to the editor
Note that the data flow is one way (editor to source file). If you make changes to the source file (.csv) while the editor is open, the editor will not be updated!
On initial load all rows are expanded so that all rows have equal length (number of cells (if necessary))
unsaved changes
indicator right from the startenabling/disabling the has header
read option will clear the undo/redo stack!
empty lines are skipped!
unsaved changes
indicator""
We try to retain quote information (default) but in some cases fields could get unquoted on save (see Retain Quote Information Rules)
Comment row (rows starting with a comment) will only export the first cell
Adding new lines to comments rows (via alt + enter) will have no effect when exporting (lines breaks are removed in comments!)
Starting with Version 0.1.0 the table has a context menu (right-click the table)
Plugin Version 0.0.11 had an issue with loading and saving files with more than \~1 MB
during parsing information about the quotes are stored
csv-edit.newColumnQuoteInformationIsQuoted
(default is not quoted)csv-edit.newColumnQuoteInformationIsQuoted
quote informationImplications of this
This can be turned off by setting csv-edit.retainQuoteInformation
to false
In this case all unnecessary quotes are removed
essentially it's just import csv and export csv
When you click on Edit CSV file
the file content is cut into pieced and transferred via [webview].postMessage
the current config is stringified and injected into the editor (webview) html
a manager stores a reference to the webview, source file uri, editor uri
in the webview the pieces are put together and the text is parsed as csv and displayed in the (handsontable) table element
When you click on apply
the current table is transformed into csv, transferred via vscode.postMessage
to the extension and written to the source file
apply
by accident, you can undo the changes in the table element (with the usual shortcuts) and apply again or open the source file and just do an undo (with the usual shortcuts)When you click on apply and save
apply
When you click in Read again
As you can see this does not scale very well with large csv files (needs to be stringified and stored the whole time)
There are some settings for this plugin. Open the VS Code Settings and search for csv-edit
Files with the extension .csv
, .tsv
should work out of the box.
You can change the file type in the bottom right corner of the editor (select language mode). This is required for unnamed/new files.
For tsv
, make sure the indention is set to tabs
.
See https://code.visualstudio.com/docs/languages/overview#_adding-a-file-extension-to-a-language
If the link is down: Search for files.associations
in the vs code settings. Then add an entry for *.xyz
to csv
.
Now the file is treated as a csv file and is recognized by the extension
Starting from version 0.10.0
the setting dragToAutoFill
defaults to excelLike
.
The other values are none
and copyOnly
.
none
is used to disable auto fill.
Setting dragToAutoFill
to copyOnly
will copy the selected cell values over and over again.
Example: 1,b,3
and you drag the handle 6 cells further will give 1,b,3,1,b,3
as auto fill values.
As you can see, there is no interpolation, the selected sequence is copied again and again.
The default setting excelLike
imitates the Excel behaviour for automatic fill values.
In most cases it will work just fine, but there may be some special cases.
In general, the following values can be filled in automatically: Numbers, month names and dates.
Similar to Excel, you can hold down the alt
key before releasing the mouse button to copy the cell values. No interpolation is carried out.
You can find a complete explanation of how automatic filling works in docs/autoFillBehavior.md
.
apply and save
an unnamed file will close the editor
renaming a file while an editor is open for that file will break the reference the the source file
if the source file content changes and the file is not in the current workspace (open folder) auto file content reload is not working
I recommend installing the Rainbow CSV
extension, the extensions play well together!
If you want to only view csv files you can go for the extension Excel Viewer. It has some more advanced sorting and filtering features.
There is one things missing...
see thirdParty
folders
There are some more in package.json
. Even if they are not referenced directly, they are used e.g. for the browser build. We copy them from node_modules
into the thirdParty
folders.
There is a command edit-csv.editWithConfig
. It can be used to open the editor with settings specified by you.
All possible settings can be found in [project root]/csvEditorHtml/types.d.ts > EditCsvConfig
. The easiest way is to copy both types EditCsvConfig
and EditCsvConfigOverwrite
and then call the extenion command like this:
vscode.commands.registerCommand('yourExtension.yourCommand', () => {
let overwriteSettings: EditCsvConfigOverwrite = {
readOption_hasHeader: "true",
//other options, auto completion enabled
}
vscode.commands.executeCommand(`edit-csv.editWithConfig`, overwriteSettings)
})
There is one problem left: the Edit CSV
button in the title bar (and the file right click menu action) will still use the settings set by the user...
For this there is the option csv-edit.hideOpenCsvEditorUiActions
. If set to true it will hide the two ui actions. This way you can create a buttom from your extension and open the editor and force your settings.
Make sure to keep the type EditCsvConfig up-to-date (in case any types change)
The extension will warn you about any unknown settings supplied but will not check the actual property values!
It will overwrite the settings configured by the user and call the same method as edit-csv.edit
(the default when the editor is opened via the Edit CSV
button).
To compile (and watch) the files in csvEditorHtml
run
tsc -w #or just tsc to transpile only once
# new terminal
cd csvEditorHtml
tsc -w #or just tsc to transpile only once
then press F5
to run the extension
When you edit csvEditorHtml/index.html
you need to manually copy the changes (everything in the body but without the scripts) into src/getHtml.ts
(past into body)
You can also open csvEditorHtml/index.html
in your favorite browser and play around (the vs code settings are not applied in the browser)
Code: MIT