Link Search Menu Expand Document

Writing CSV - Essential Secrets of CSV

Welcome to this new course Essential Secrets of CSV here at ByteScout. A CSV or a comma-separated value is a file format that is one of the common ways of storing records in a portable and simple format. It looks a lot like a plain text file that holds data in table format.

The information is organized with one record on each line, or you can say each line is like a row in a table, and columns are separated by a comma. In short, it is a delimited text file that uses a comma with two separate values, hence the name Comma Separated Value (CSV).

Writing CSV

Now without going much into the theory let's write one CSV file and try to understand it. Let's assume that we need to create a sample CSV file that will represent patient information and we'll need to import it into one application. Let's jump into it.

Here in the left pane, you can see that the extension of the comma-separated file is dot CSV, and by the way, it is not always necessarily the case. It can also be the dot TXT file, which is the sample text file that contains the patient information like patient ID, Name, Chart Number, who is the primary care physician, and so on.

Writing CSV Files

Now let's write the CSV file for this information.  As I said a CSV file holds the record in a table format, here in this ImportPatient.CSV file let's define the column name as header separated by a comma. As per this text file, the first column is the patient ID followed by the patient name. Let's start by defining this column in this file (id,PatientName,Gender,ChartNo,HomePhone,WorkPhone,Primary_Physician), and then in the next line, we have subsequent rows containing records separated by a comma.

As per this TXT file, 1010 is our first patient id. Let's write down the same in this CSV file (1010, John Doe,Male, JH1547,201-551-1234,-,Dr. Tom Rigerman). Now the same way, let's define the other row for the next patient (1020, Anna Smith, Female,MK2517,201-552-5634,201-552-6734,Dr. Peter Jones). Then for the last patient (1030, James Butt,Male,PK9617,504-621-8927,504-845-1427,Dr. Marc Rigerman) and save the file.

How to Write CSV

So our CSV file is ready. One of the big advantages of the CSV file is that it can be easily managed via Microsoft Excel or some similar software. Now go to the file location of this file by right-clicking on ImportPatient.csv and select Reveal in the File Explorer option. When I double click on the ImportPatient.csv file, it is opening in Microsoft Excel and you can see how beautifully our data is displayed in this Excel sheet.

Other useful articles:


Back to top

© , Learn CSV — All Rights Reserved - Terms of Use - Privacy Policy