Bug 168433 - The ScriptForge ImportCSVFile method creates an error when the second but last value contains a comma in a CSV file.
Summary: The ScriptForge ImportCSVFile method creates an error when the second but las...
Status: CLOSED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
3.3.0 release
Hardware: Other Windows (All)
: medium normal
Assignee: Jean-Pierre Ledure
URL:
Whiteboard: target:26.2.0 target:25.8.2.2 target:...
Keywords:
Depends on:
Blocks:
 
Reported: 2025-09-16 17:22 UTC by bettina.wiskott@rousset.com
Modified: 2025-10-12 08:28 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
LibreOffice Base file with a form to allow you to import a CSV file. (13.33 KB, application/vnd.sun.xml.base)
2025-09-16 17:35 UTC, bettina.wiskott@rousset.com
Details
The CSV file that cannot be imported using the ScriptForge ImportCSVFile method. (170 bytes, application/vnd.ms-excel)
2025-09-16 17:39 UTC, bettina.wiskott@rousset.com
Details

Note You need to log in before you can comment on or make changes to this bug.
Description bettina.wiskott@rousset.com 2025-09-16 17:22:32 UTC
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
Comment 1 bettina.wiskott@rousset.com 2025-09-16 17:35:15 UTC
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.
Comment 2 bettina.wiskott@rousset.com 2025-09-16 17:39:37 UTC
Created attachment 202848 [details]
The CSV file that cannot be imported using the ScriptForge  ImportCSVFile method.
Comment 3 Julien Nabet 2025-09-17 08:16:23 UTC
Jean-Pierre: thought you might be interested in this one since it concerns ScriptForge
Comment 4 Werner Tietz 2025-09-17 14:56:30 UTC
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.
Comment 5 Werner Tietz 2025-09-17 15:15:54 UTC
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 )
```
Comment 6 Jean-Pierre Ledure 2025-09-18 08:21:24 UTC
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
Comment 7 bettina.wiskott@rousset.com 2025-09-18 19:03:35 UTC
(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.
Comment 8 Jean-Pierre Ledure 2025-09-20 11:39:47 UTC
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 :)
Comment 9 Commit Notification 2025-09-20 14:20:42 UTC
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.
Comment 10 Commit Notification 2025-09-20 15:46:53 UTC
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.
Comment 11 Commit Notification 2025-09-21 08:48:28 UTC
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.
Comment 12 Commit Notification 2025-09-29 14:57:49 UTC
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.
Comment 13 bettina.wiskott@rousset.com 2025-10-11 18:34:59 UTC
Dear Jean-Pierre,
At last I am back from vacations and can test your correction. It works now indeed perfectly.
Thanks so much for your very quick answer and your push to the best release possible. It makes a difference to my users.
Thanks again.
Bettina