matta
May 31, 2025, 8:10am
1
I have tried using the File Headers as defined in the Anki manual.
However, if I put them in the top rows of my spreadsheet, when I save or export the spreadsheet as CSV, LibreOffice Calc adds commas at the end of these lines. Anki Import then ignores these lines because of these commas.
Having to open up the CSV and clear out these commas takes time.
Would it be possible to have Anki Import ignore any delimiters after #key:value , if those delimiters were specified by #separator:Comma ? This would mean that we could simply save our spreadsheets as CSVs and then import then immediately into Anki.
Perhaps another option, might be to use some other terminating character (e.g. semicolon) for these #key:value lines.
llama
May 31, 2025, 9:44am
2
This is already how it works in the 25.05 betas
2 Likes
I had reported the same thing in
opened 08:30PM - 10 Mar 25 UTC
closed 11:56AM - 19 Mar 25 UTC
> # Steps to reproduce
> 1. Open LibreOffice Calc and paste the following into i… t:
> ```
> #separator:Comma
> This is a question. And this is the answer. Test::CSV
> This is a question 2. And this is the answer 2. Test::CSV
> This is a question 3. And this is the answer 3. Test::CSV
> ```
> It will look like this:
> 
>
> 2. Safe the file as *test.csv* and make it comma separated:
> 
> 3. Open Anki.
> 4. Import test.csv and notice that anki thinks the file is colon separated:
> 
>
> # Additional info
>
> The *test.csv* looks like this:
> ```
> #separator:Comma,,
> This is a question.,And this is the answer.,Test::CSV
> This is a question 2.,And this is the answer 2.,Test::CSV
> This is a question 3.,And this is the answer 3.,Test::CSV
> ```
>
> Removing the trailing commas in the first line (without modifying the tags *Test::CSV*) results in this:
> ```
> #separator:Comma
> This is a question.,And this is the answer.,Test::CSV
> This is a question 2.,And this is the answer 2.,Test::CSV
> This is a question 3.,And this is the answer 3.,Test::CSV
> ```
> And:
> 
> As you can see Anki now correctly identifies the separator and the field greys out as well.
>
> # Expected Behavior
> Anki should be able to handle the .csv file headers correctly. I shouldn't have to manually alter the first few lines every time I want to import a .csv.
>
> # Actual Behavior
> Anki doesn't correctly apply the file headers, without prior manual modifications.
>
> # Version
> ```
> Anki 25.02 (8fc822a6) (src) (ao)
> Python 3.9.18 Qt 6.6.2 PyQt 6.6.1
> Platform: Linux-6.12.12-amd64-x86_64-with-glibc2.40
>
> ===Add-ons (active)===
> (add-on provided name [Add-on folder, installed at, version, is config changed])
> AnkiWebView Inspector ['31746032', 2023-06-27T21:26, 'None', '']
>
> ===IDs of active AnkiWeb add-ons===
> 31746032
>
> ===Add-ons (inactive)===
> (add-on provided name [Add-on folder, installed at, version, is config changed])
> Image Occlusion Enhanced ['1374772155', 2022-04-09T09:15, 'None', '']
> Review Heatmap ['1771074083', 2022-06-30T03:43, 'None', '']
> Study Time Stats ['1247171202', 2024-02-24T17:59, 'None', '']
>
> ```
Originally reported here: https://forums.ankiweb.net/t/bug-file-headers-not-working-correctly-with-csv-files/56243?u=anon_0000
llama solved it in
main
← iamllama:csv-sniffer
opened 10:46PM - 12 Mar 25 UTC
Resolves #3853
Anki's current csv delimiter heuristic works by looking for po… tential delimiters in ascending expected frequency (`\t`, `|`, `;`, `:`, `,`, ` `) in the first 8kb. While a wrong guess isn't necessarily a problem since the delimiter can be changed in the import options page, hierarchical tags (::) throw a wrench in this, as pointed out by @GithubAnon0000. And it's a common enough usecase that anki maybe shouldn't penalise. I imagine this was also foreseen by Rumov when he left a todo 3 years ago
This pr proposes pulling in and using the ~~csv-sniffer~~ crate, which is able to correctly deduce the delimiter for the samples in #3588 and #3853 in a multiplatform manner
EDIT: replaced [csv-sniffer](https://github.com/jblondin/csv-sniffer) with [qsv-sniffer](https://github.com/jqnatividad/qsv-sniffer), a fork that fixes some of the former's issues. However, not only is it more bloated than csv-sniffer, it still (unsurprisingly) has samples that it fails on: https://github.com/jblondin/csv-sniffer/issues/18. Not sure if this is worth pursuing
1 Like
matta
May 31, 2025, 6:20pm
4
Thank you, @Anon_0000 and @llama !
1 Like