Creating .csv, .tsv, .xls and .xlsx files for use with Slacktables

May 30, 2024

You can upload files in four different file formats to Slacktables: .csv, .tsv, .xls and .xlsx. Regardless of which file format you choose, there are certain things you should keep in mind to ensure smooth operation with Slacktables.

Difference between .csv, .tsv, .xls and .xlsx files

The .csv stands for "comma-separated values" and .tsv stands for "tab-separated values". These are simple text file formats where each value is separated by a comma or a tab respectively. The .xls and .xlsx are Excel file formats, with .xlsx being the newer version. These files can contain complex data like formulas, charts, and other features that are not supported by .csv and .tsv files.

How to create .csv or .tsv file

.csv and .tsv files can be created in any text editor, including notepad on windows. You can also create these files using a spreadsheet software. Simply enter your values in a spreadsheet, and click 'File -> Save as' and choose "csv" as the file format before saving. If you do not want to use a spreadsheet software, open any text editor (eg: notepad) and enter each value separated by commas. Each row in the table should go to a different line in the file. Here's a sample csv file:

Name,Age,Salary Laura,21,5000 Kevin,31,3000 John,55,9000

To save the file as csv rather than a normal text file , click "File" -> "Save As" and in the resulting dialog box, select "Comma Separated Values (. csv)" from the "Save as type" drop-down menu. In the above example, each line has values separated by a comma. The first line in a tsv or csv file is special and should contain the column names. If you omit this line, or if you decide to put the column names in the second line and leave the first line empty for some reason, slacktables will not be able to figure out the column names correctly. So remember, the first line should always contain the column names!

Left: A microsoft excel file with our data. We can choose to save this spreadsheet as a csv, tsv, xls or xlsx file. Right: Our data written as comma-separated values (i.e as csv) in a text editor. When we save this file, we have to make sure that the filename ends with ".csv"

Another point worth noting is that every line has the same number of values. This is important! If you have a missing value, add a blank space between the commas. For example, imagine that you do not know Kevin's salary. Your csv file then should look like:

Name,Age,Salary Laura,21,5000 Kevin,31, , John,55,9000

Notice the commas surrounding a blank space on line 3? Without that blank space, Slacktables will treat line 3 as malformed - you have 3 columns but you only supplied 2 comma-separated values in line 3 - and throw an error! A .tsv file is very similar to a .csv file, except that the commas are replaced by tabs:

Name Age Salary Laura 21 5000 Kevin 31 3000 John 55 9000

The csv and tsv examples mentioned above will be rendered similary by Slacktables. The differences in file formats have no impact on the rendered table.

How to create .xls and .xlsx files

Creating .xls and .xlsx files require you to have Microsoft Excel or a similar spreadsheet software. Just like csv and tsv files, the first row should contain the name of the columns. You can save your workbook as .xls or .xlsx from the 'Save As' option in the File menu. However, keep in mind that when you save a workbook in another file format, some of its formatting, data, and features might not be saved.

Examples of valid and invalid file content

As mentioned earlier, the first line of your file should always contain the column names. Each subsequent line should contain the same number of values as there are columns. If a value is missing, you should still include a comma (for csv) or a tab (for tsv) to indicate the missing value. Here's an example of a valid csv file:

Name,Age,Salary Laura,21,5000 Kevin,31, , John,55,9000

And here's an example of an invalid csv file:

Name,Age,Salary Laura,21,5000 Kevin,31 John,55,9000

In the invalid example, the second line only has two values instead of three. This will cause an error when trying to render the file as a table in Slacktables.