Description: The following CSV file crashes at the thirst line ("Massimo, Paolo", ...) : FirstName,LastName,Address Heidi,Unterberger,"Bottom Avenue,6" Leila,"Mungo, Tiga",Top Street 4 "Massimo, Paolo",Cantone,Triaudes Place 11 John,Smith,5 Main Street Steps to Reproduce: 1.Create a CSV file with the lines provided in the "Description" above. 2.Create a basic program that uses the ScriptForge ImportCSVFile method and try to import the created CSV file. Actual Results: The following error will be shown: Library : ScriptForge Service : Array Method : ImportFromCSVFile Arguments: FileName, [Delimiter=","], [DateFormat=""] The given file could not be parsed as a valid CSV file. « File name » = C:\Users\Administrator\Documents\CSVImportProblemFile.csv Line number = 4 Content = "Massimo, Paolo",Cantone,Triaudes Place 11 THE EXECUTION IS CANCELLED. Expected Results: Import the CSV normally into an array. Note that if I remove the comma in "Massimo, Paolo" (writing "Massimo Paolo"), the file imports without issues. Reproducible: Always User Profile Reset: Yes Additional Info: I use the following macro: Sub ImportCSVFile (oEvent As Object) Dim oButtonImport As Object Dim oForm As Object Dim oFileSelected As Object Dim InArray As Variant oButtonImport = oEvent.Source.Model oForm = oButtonImport.Parent GlobalScope.BasicLibraries.loadLibrary("ScriptForge") oFileSelected = oForm.getByName("FileSelected") InArray = SF_Array.ImportFromCSVFile(oFileSelected.Text, ",") MsgBox ("Import successful.",,"INFORMATION") End Sub Help - About LibreOffice: Version: 25.2.5.2 (X86_64) / LibreOffice Community Build ID: 03d19516eb2e1dd5d4ccd751a0d6f35f35e08022 CPU threads: 4; OS: Windows 10 X86_64 (10.0 build 19045); UI render: Skia/Raster; VCL: win Locale: en-GB (en_GB); UI: en-GB Calc: threaded
Created attachment 202847 [details] LibreOffice Base file with a form to allow you to import a CSV file. Create a CSV file with the following content: FirstName,LastName,Address Heidi,Unterberger,"Bottom Avenue,6" Leila,"Mungo, Tiga",Top Street 4 "Massimo, Paolo",Cantone,Triaudes Place 11 John,Smith,5 Main Street Use the "Browse..." button to locate the file. Press the "Import file" button to try to import the file. The error will show.
Created attachment 202848 [details] The CSV file that cannot be imported using the ScriptForge ImportCSVFile method.
Jean-Pierre: thought you might be interested in this one since it concerns ScriptForge
Hallo You may use this simple python-script…: ``` from csv import reader, Sniffer def ImportCSVFile(oEvent): oButtonImport = oEvent.Source.Model oForm = oButtonImport.Parent file_path = oForm.getByName("FileSelected").Text with open(file_path, encoding="utf_8_sig") as csv_file: dialect = Sniffer().sniff(csv_file.read(2000)) with open(file_path, encoding="utf_8_sig") as csv_file: data = [row for row in reader(csv_file, dialect=dialect)] print( data ) ``` … as long as SF cannot fix the bug.
Update: ``` from csv import reader, Sniffer def ImportCSVFile(oEvent): oButtonImport = oEvent.Source.Model oForm = oButtonImport.Parent file_path = oForm.getByName("FileSelected").Text with open(file_path, encoding="utf_8_sig") as csv_file: dialect = Sniffer().sniff(csv_file.read(2000)) csv_file.seek(0) data = [row for row in reader(csv_file, dialect=dialect)] print( data ) ```
Bug confirmed. Version: 25.2.5.2 (X86_64) / LibreOffice Community Build ID: 03d19516eb2e1dd5d4ccd751a0d6f35f35e08022 CPU threads: 6; OS: Linux 6.8; UI render: default; VCL: kf5 (cairo+xcb) Locale: fr-BE (en_US.UTF-8); UI: en-US Calc: threaded
(In reply to Werner Tietz from comment #5) > Update: > ``` > from csv import reader, Sniffer > > def ImportCSVFile(oEvent): > oButtonImport = oEvent.Source.Model > oForm = oButtonImport.Parent > file_path = oForm.getByName("FileSelected").Text > > with open(file_path, encoding="utf_8_sig") as csv_file: > dialect = Sniffer().sniff(csv_file.read(2000)) > csv_file.seek(0) > data = [row for row in reader(csv_file, dialect=dialect)] > print( data ) > ``` Thanks for your code. I appreciate your help, but I have no knowledge of Python. I might try it though, eventually.
Patch on the way ... See https://gerrit.libreoffice.org/c/core/+/191227 Thanks for reporting the bug and helping me to make our software even better :)
Jean-Pierre Ledure committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/cf57cf042aaa863ff6a730e79df1df1a5dbefc9e ScriptForge fix tdf#168433 array.ImportFromCSVFile It will be available in 26.2.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Jean-Pierre Ledure committed a patch related to this issue. It has been pushed to "libreoffice-25-8": https://git.libreoffice.org/core/commit/445d1ece2922bd6cf278b35c62cef9bb51879417 ScriptForge fix tdf#168433 array.ImportFromCSVFile It will be available in 25.8.3. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Jean-Pierre Ledure committed a patch related to this issue. It has been pushed to "libreoffice-25-2": https://git.libreoffice.org/core/commit/1cffbd92d6e9f57ed42dc3b461b44c603a33665f ScriptForge fix tdf#168433 array.ImportFromCSVFile It will be available in 25.2.7. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Jean-Pierre Ledure committed a patch related to this issue. It has been pushed to "libreoffice-25-8-2": https://git.libreoffice.org/core/commit/55c76d699afae6facfff0dd2662fff6b5fd9c549 ScriptForge fix tdf#168433 array.ImportFromCSVFile It will be available in 25.8.2. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.