How to Edit or create Open CSV file in Pascal lazarus / 21-General ---------------------------------------------------------------------- RaviMore9 · 2022-10-28 07:40 Hi, I am looking for the method or source code to edit or create the csv file which is opened. Is it possible to edit the open file in pascal. System details are as follows: 1. operating system  :   Windows 10 Enterprise 2. version of operating system : 20H2 3. version of Lazarus IDE :2..2.2 ---------------------------------------------------------------------- KodeZwerg · 2022-10-28 08:22 CSV or CommaSeperatedValues read in with any method, doing a split on a comma and you have what you want. write, i would use a TStringList, add every value to the list, on actual writing i would convert the TStringList back to a basic string and add a comma after each element ---------------------------------------------------------------------- Nicole · 2022-10-28 08:26 I would use TMemo or TStringList. Just use myMemo.loadfromFile('my.cvs'); edit it and myMemo.saveToFile('my.cvs'); ---------------------------------------------------------------------- wp · 2022-10-28 08:30 If you prefer a grid-like user interface, similar to Excel, you could install fpspreadsheet (use online-package-manager to do this) and load the csv file into a TsWorksheetGrid (you must have unit fpsCSV in "uses" to get access to the CSV reader/writer): - https://wiki.lazarus.freepascal.org/FPSpreadsheet_tutorial:_Writing_ a_mini_spreadsheet_application - https://wiki.lazarus.freepascal.org/FPSpreadsheet ---------------------------------------------------------------------- Jorg3000 · 2022-10-28 08:49 If it is to be changed only on the program side, the simplest solution is TCSVDocument, see also .SaveToFile() Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses csvDocument; var csv: TCSVDocument;begin  csv:=TCSVDocument.Create;  csv.Delimiter:=';';  csv.LoadFromFile('Test.csv');  ShowMessage(csv.Cells[2,2]);  csv.Free;end; ---------------------------------------------------------------------- jcmontherock · 2022-10-28 09:32 I am using TStringGrid with visible:= False. With it you can easily read/write file and parse/change data of csv files. ---------------------------------------------------------------------- RaviMore9 · 2022-11-01 04:27 I am not able to edit CSV file if it is already open . Is it possible to update the same CSV file which is already opened. I am getting following error while generating CSV file: The process can not access the file because it is being used by another process. I have implemented the following code to generate csv file:: var  DestFile:String;        fd:TTextBuffer;  begin DestFile:= CSVFileName.csv if DestFile = '' then exit;     fd:=TTextBuffer.create(DestFile,B_WRITE);     fd.Rewrite;     if old then mode:=EXPORT_OLDVERSION else mode:=0;     DecimalSeparator:='.';     fd.writeln('CSV file data, Data1, data2');     fd.writeln('CSV file data1, Data1, data2')    fd.flush;    fd.free;   end; ---------------------------------------------------------------------- KodeZwerg · 2022-11-01 08:30 Quote from: RaviMore9 on November 01, 2022, 05:27:18 amI am not able to edit CSV file if it is already open . Is it possible to update the same CSV file which is already opened. I am getting following error while generating CSV file: The process can not access the file because it is being used by another process.When a file, no matter what type of file, is opened not shared for writing, you will never be able to write as long a handle with that access rights is opened. That is a wanted behavior and you can not do anything beside closing the other app/opened handle to the file.