Any means of autoimporting CSV files into Calc?

Beause you are just a manipulative coin bro.

1 Like

I’m a capitalist. Are the LIbreoffice developers all opposed to capital markets? Are you some type of Communists, like Mozilla?
.
Literally, all cryptocurrency is is equity markets with a bunch of traditionally left wing jobs, in compliance and regulation, that introduce capital inefficiency, automated out of existence. Those jobs are replaced by computers. It literally let’s everyone with some savings play venture capitalist. It’s literally no different from the US equity markets, or any equity market. There are just as many scams as you find in regulated markets.
.
That’s not to mention the fact sending large amounts of money, and making large financial transactions have cheaper fees than tradfi. All of the financial markets are filled with fraud. It’s kind of the standard when dealing with money.

First. You are off topic. No more posts about unrelated stuff please, you are close to the line.
.
You are talking to users here, not developers.
.
You are welcome to use whatever office suite you like.
.
If it isn’t a high priority for most people (it isn’t) then you may pay someone to add the option of importing csv with the previous settings to LibreOffice.

I’m sorry.
.
I’m just surprised this entire topic gets responded with hostility by a vocal part of the userbase and developers. By looking over that bug report it looks like the topic causes flame wars. Sounds like it has something to do with region and language spoken for whether CSVs import easily or not. I just find it strange there’s a group so opposed to this when even the people believing the dialogue prompt is the right choice most likely have a general case that would work for most imports.
.
I understand it’s not a priority. I don’t even really need it since there’s a workaround. I just seems like an easy feature to add if anyone felt like it. It’s just a config file parser, and it looks like most of the code required to implement the feature is already there. I might do it myself if I have the time.

Some of the hostility comes from using Excel in a country that does not use USA type date formatting. In New Zealand, when Microsoft removed the text import dialogue, importing CSVs became an exercise in vigilance.
With date columns, Excel would convert anything that looked like a date to USA format where it could, the rest of the column was left as text in NZ date format causing damage to data as dates were wrongly created. Probably Excel has got better at reading locale from its own settings but I am not interested in buying it just to test that.
.
I had to create macros to import CSVs that were exported from our database to avoid such damage. You can create your own macro to import CSV if it is always the same layout. The book by Pitonyak is a good start for understanding LibreOffice macros, www.pitonyak.org/oo.php

2 Likes

In countries such as the US, UK and Australia, the default list separator is a comma, so you get CSV comma delimited. In non-English speaking European countries, a comma is reserved for the decimal symbol, and the list separator is generally set to semicolon. Based on this, your demand is quite unreasonable for the simple reason that at some point the translation has to be done anyway before the listing is printed on the screen or on paper. So now the question turns upside down: who are there more in the world, ordinary consumers or people working in the financial sector? And last but not least, who will end up footing the bill?

1 Like

While I can see the polarized opinions, I fail to see the stated ā€œhostility by … developersā€. Could you please point to the source of this specific part of your statement?

For my part, I see greed (even a bit of McCarthyism) in some of the opinions. Everything should be available to them for free. As far as I know, when running a business, for example, investments in software are tax deductible.
Well, it seems to be very common for deep rooted capitalists, for example, when they’re driving their luxury car and the road has potholes, they complain that nothing works, but at the same time they demand tax breaks and foremost see commies everywhere :wink:

OK, let’s dumb down further.
What is this: 123,456 :question:

Well, if you add a € sign after that, it’s just pocket money.
But if you add a $ sign in front of it, it’s quite big pocket money :wink:

Wrong. It’s 2 integers separated by a comma. :stuck_out_tongue:

1 Like

That was pretty good :woozy_face:

One trick, Microsoft used to play, is treating numeric strings as numbers. This way, you get different numeric values from the same text data, depending on Excel’s locale setting, while chances are pretty good that the dumb user does not take notice of wrongly imported data until he/she tries to SUM or sort these data.

Meanwhile, Calc submitted to this madness per default. A fresh profile reveals that ="1/2/34" + "1" yields either 1934-01-03 for the USA or 1934-02-02 for the bloody rest of the world.
This can be turned off via Tools>Options>Calc>Formula>Details… The strict setting (raise #VALUE!) lets you take notice of strange things going on in that sheet. The default is the same as Excel’s.
At least, LO allows adjusting this setting for individual documents.

A quick research about MS Excel, reveals that csv is properly imported when the numeric strings match with the locale setting. Same as Calc.
I could not find a single description about Excel importing non-matching data. I guess, that dumb user clicks [OK] anyway and happily imports text into the smart spreadsheet.
txt2num.ods (18.2 KB)

1 Like

3 lines from a bank statement of mine. Would be interesting to know, how a non-german Excel imports this stuff automatically:

27.01.2025;xxxxxxxxxxxxxxxxxxx xxxxxxxxxxx xxxxxxxxx-xxxxx;"xxxxxxxxxxxxxxxxxxxxxx; xxxxxxxxxxxxxxxxxxx xxxxxxxxxxx xxxxxxxxx-xxxxx; xxxxxxxxxxx xxxxxxxx; ";"810,49";"2.429,06"
27.01.2025;xxx xx;"xxxxxxxxxxx xxxxxx; ; xxx xx; 311501; xxx: xxxxxxxx; xxxx: xx21512202000068660008";"-792,70";"41.618,57"
27.01.2025;"xxxxxx xxxxxxx xxxx xx xxx xxxxxxxx 20, 33333 xxxxxxxxx";"xxxx-xxxxxxxxxxxxxxxx; xxxxxx xxxxxxx xxxx xx xxx xxxxxxxx 20, 33333 xxxxxxxxx xxxxxxx; xxxxxxx xxx 200019; xxxxxxxx xx xx2299700000008303; xxx xx xxx xx: xxxxxxxxxxx xxxxxx-xxxxxxxx: xxxxxxxxxxx";"-94,61";"42.411,27"
23.01.2025;;"xxxxxxxxxxxxxxxxxxxxxx; xxxxxxxxxx xxx xxxxxxxxx xxxx; xx 2085799, xxxxxx, 20107511246; ";"45,66";"2.505,88"
1 Like

Would be funny if it just works. The W3C published standards for this ten years ago. Wonder if Microsoft and Google just need to pay one guy $100k to fix the problem. We’ll probably get AIs that can correct the errors before fixing a formatting error.

REM  *****  BASIC  *****

Sub ReadCSV()
	
	' This works if reading an EU .csv file and
	' writing the content to an en-US spreadsheet,
	' but it's not absolutely all-encompassing .
	
    GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
    Set FSO = CreateScriptService("FileSystem")
    Dim fullPath As String
    Dim folderPath As String
    Dim fullPathUrl As String
    
    Select Case OSName
        Case "WIN"
            folderPath = ConvertToURL(Environ("UserProfile") & "\Documents\CSV_files")
            fullPath = (Environ("UserProfile") & "\Documents\CSV_files\CSV_test.csv")            
        Case "LINUX", "OS2","UNIX","MAC"
            folderPath = ConvertToURL("/home/user/Documents/CSV_files")
            fullPath = folderPath & "/CSV_test.csv"
        Case Else
    End Select
    
    fullPathUrl = ConvertToURL(fullPath)
    
    If Not FSO.FolderExists(folderPath) Then
        MsgBox "Folder " & folderPath & " not found."
    End If

    Set FSO = Nothing
    Dim strContent As String

    strContent = ReadFromFile(fullPathUrl)

    If strContent = "" Then
    	If OSName = "WIN" Then
			MsgBox "File not found " & fullPath
		Else
			MsgBox "File not found " & fullPathUrl
		End If
		Exit Sub
    End If

    Dim  strSeparator As String
    
    IF InStr(strContent, ";") > 0 Then
    	strSeparator = ";"
    End If
    
    Dim isAllowed  As Boolean
	Dim oDoc As Object
	Dim oSheet As Object
	Dim oCell As Object
 	oDoc = ThisComponent
 	oSheet = ThisComponent.CurrentController.getActiveSheet()

	tempArray = Split(strContent, chr(13) & chr(10)) : strContent = "" 
	
	For i = Lbound(tempArray) To Ubound(tempArray)
	
		Dim temp2Array() As String 
		temp2Array() = Split(tempArray(i), strSeparator)
		 
		For j = Lbound(temp2Array) To Ubound(temp2Array)
			
			oCell = oSheet.getCellByPosition(j, i)
			isAllowed = True: doCnt = 32
			Do 
				doCnt = doCnt  + 1
				Select Case doCnt
					Case 33 To 42, 47, 58 To 126
						If InStr(temp2Array(j), chr(doCnt)) > 0 Then
							isAllowed = False : Exit Do
						End If
					Case Else
				End Select
			Loop Until doCnt =  126

			If strSeparator = ";" And IsAllowed Then
				If IsNumeric(Left(temp2Array(j), 1)) Then			
					temp2Array(j) = Replace(temp2Array(j), ",", ".")
					oCell.HoriJustify = com.sun.star.table.CellHoriJustify.RIGHT
				End If
			
				If IsNumeric(Left(temp2Array(j), 1))  And InStr(temp2Array(j), " ") > 0 Then
					temp2Array(j) = Replace(temp2Array(j), " ", ",")
				End If
			Else
				oCell.HoriJustify = com.sun.star.table.CellHoriJustify.LEFT	
			End If
		
			oCell.setString(temp2Array(j))
			
		Next j
		
		Erase temp2Arry()
		
	Next i
	
	Erase tempArray()
	
End Sub

Function ReadFromFile(sFileNameUrl As String) As String

    Dim FSO As Object
    
    GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
    Set FSO = CreateScriptService("FileSystem")
    
    If FSO.FileExists(sFileNameUrl) Then
        Dim inputFile As Object        
        Set inputFile = FSO.OpenTextFile(sFileNameUrl)
        ReadFromFile = inputFile.ReadAll()
        inputFile.CloseFile()
        Set FSO = Nothing
        Exit Function
    Else
        Set FSO = Nothing
        ReadFromFile = ""
    End If

End Function

Function OSName As String

    With GlobalScope.Basiclibraries
        If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
    End With

    Dim keyNode As Object
    keyNode = Tools.Misc.GetRegistryKeyContent("org.openoffice.Office.Common/Help")
    OSName = keyNode.GetByName("System")

End Function
1 Like

Writing perfectly working macro code to import one particular flavour of csv is trivial. This may be what Mr. Coin Bro wants us to do for free. The impertinence is that he tries to tell us what Excel is capable to do.
Next time he will tell us that Excel’s AI assistant can analyze a column of date strings, which is impossible when you import dates with no day number >12. I’m confident that Excel happily imports strings without bothering the user with any prompts.
Just like Calc, Excel prompts for import options every time you open a csv. It does not import anything automatically. Anything I found about Excel guessing import parameters is trivial stuff where everything in the csv matches the office locale.
This discussion about 10, 20, may be 100 mouse clicks per working day has no purpose other than wasting our time.

Sub Open_Specific_Csv()
file = getFileFromFilePickerDialog("~/Downloads/*.csv"))
specific_options = "59,34,ANSI,1,,1031,false,true,true,false,false,0,false,false,true"
Open_CSV file, specific_options
End Sub

Sub Open_CSV(sURL As String, sFilterOptions As String)
Dim aProps(1) as new com.sun.star.beans.PropertyValue
aProps(0).Name = "FilterName"
aProps(0).Value = "Text - txt - csv (StarCalc)"
aProps(1).Name = "FilterOptions"
aProps(1).Value = sFilterOptions
doc = StarDesktop.loadComponentFromURL(file, "_default", 0 aProps())
End Sub

The above code reliably opens the weird sample data from my banking account because of the specific_options passed to the working routine together with a file URL.
Reading the filter options string for a correctly loaded csv is trivial:

Sub showFilterOptions()
Dim args(),i%
   args() = StarDesktop.CurrentComponent.getArgs()
   for i = 0 to uBound(Args())
      if args(i).Name = "FilterOptions" then inputbox args(i).Name,"",cStr(args(i).value)
   next
End Sub
1 Like

In theory, the following Python code is able to guess the import parameters of a given csv sample and read the contents:

import csv
dialect = csv.Sniffer().sniff(csvfile.readline(), [',',';'])
csvfile.seek(0)  
data = csv.reader(csvfile, dialect)

But having the data of a csv, has nothing to do with importing them into an arithmetic calculator.

1 Like

It’s just bad UI/UX design. Anything over 1 second of loading interrupts flow of thought with 0.1 seconds being the ideal. Not going through that prompt every time makes it more likely for Libreoffice to hit the ideal operating conditions according to research on loading software going back to the 60s. Achieving that goal through config files that cover most of the major regions, including Germany, would be ideal.
.
This is a common problem with open source software and the main issue preventing wider adoption. It’s mainly that developers are not interested in solving UI/UX problems so they do not allocate resources towards it to hire the devs that do work on that stuff. It’s not necessarily expensive to do either. I might work on a solution for this if I have the time. But, it’s probably only going to work for the US since those are the csv files I’m familiar with, unless there’s an international effort to address this.
.
I wouldn’t give money to the Document Foundation unless I know how much they have. Wikipedia and Mozilla keep asking for users to donate, and Wikipedia has $255 million and Mozillia has $826 million. Most of that money they allocate towards political causes with a very small fraction going towards development. It’s not even going towards political causes that help open source.
.
That’s basically why I’d prefer investor oversight on open source organizations since the capital is not always being used efficiently to fund development once they’re well funded. What’s going on in the US currently is a bunch of software businesses devoted resources towards political causes that do not benefit their userbase, and they’re all going bankrupt from it. They basically hired a bunch of bureaucrats to talk about improving the diversity of their workforce with $100k to $600k salaries, which does nothing to reduce business expenses, nor improve diversity. when 100 of them should have given $10k to the Document Foundation to fix some UI/UX issues to significantly reduce costs and improve profit margins by no longer having to use Excel, and hired devs to spend a year working on these issues.

Indeed, the Python module is able to guess the line breaks, the column delimiter and the string delimiter, splitting my sample data into this:

['27.01.2025', 'xxxxxxxxxxxxxxxxxxx xxxxxxxxxxx xxxxxxxxx-xxxxx', 'xxxxxxxxxxxxxxxxxxxxxx; xxxxxxxxxxxxxxxxxxx xxxxxxxxxxx xxxxxxxxx-xxxxx; xxxxxxxxxxx xxxxxxxx; ', '810,49', '2.429,06']
['27.01.2025', 'xxx xx', 'xxxxxxxxxxx xxxxxx; ; xxx xx; 311501; xxx: xxxxxxxx; xxxx: xx21512202000068660008', '-792,70', '41.618,57']
['27.01.2025', 'xxxxxx xxxxxxx xxxx xx xxx xxxxxxxx 20, 33333 xxxxxxxxx', 'xxxx-xxxxxxxxxxxxxxxx; xxxxxx xxxxxxx xxxx xx xxx xxxxxxxx 20, 33333 xxxxxxxxx xxxxxxx; xxxxxxx xxx 200019; xxxxxxxx xx xx2299700000008303; xxx xx xxx xx: xxxxxxxxxxx xxxxxx-xxxxxxxx: xxxxxxxxxxx', '-94,61', '42.411,27']
['23.01.2025', '', 'xxxxxxxxxxxxxxxxxxxxxx; xxxxxxxxxx xxx xxxxxxxxx xxxx; xx 2085799, xxxxxx, 20107511246; ', '45,66', '2.505,88']

That is 4 arrays in [brackets] with 5 strings each.
Having 5 strings per line does not help us in any way to interprete the numerals correctly.

At this point we could do what I think, Excel does: Interprete strings of digits with the decimal delimiter of the current locale and dump the dates as strings if they do not match the locale. Don’t prompt for anything because our venture capitalists don’t give a shit.