Text Files
只要满足某些条件,任何包含用逗号、分号或制表符分隔的字段的纯文本文件都可以导入到 Anki 中。
Any plain text file that contains fields separated by commas, semicolons or tabs can be imported into Anki, provided some conditions are met.
- 文件必须是纯文本(myfile.txt)。其他格式,如 myfile.xls、myfile.rtf、myfile.doc,必须先保存为纯文本文件。
The files must be plain text (myfile.txt). Other formats like myfile.xls, myfile.rtf, myfile.doc must be saved as a plain text file first.
- 文件必须采用 UTF-8 格式(请参阅下文)。
The files must be in UTF-8 format (see below).
- 第一行要定义了分隔字符-如果 Anki 在第一行中找到了“;”,它将使用“;”,如果它找到逗号,则使用逗号,等等。
The first line also defines the separating character – if Anki finds a
;
on the first line it will use that, if it finds a comma it’ll use that, etc. - Anki 通过查看第一行(未注释)来确定文件中的字段数。如果文件中的某些后续记录包含较少的字段,则 Anki 会将丢失的字段视为空白。如果某些记录包含额外的字段,则不会导入额外的内容。
Anki determines the number of fields in the file by looking at the first (non-commented) line. If some of the later records in the file contain fewer fields, Anki will treat the missing fields as if they were blank. If some of your records contain extra fields, the extra content will not be imported.
文本文件中的字段可以映射到笔记中的任何字段,包括标记字段。导入时,可以选择文本文件中的哪个字段与笔记中的哪个字段相对应。
Fields in your text file can be mapped to any field in your notes, including the tags field. You can choose which field in the text file corresponds to which field in the note when you import.
导入文本文件时,你可以选择将卡片放入哪个牌组。请记住,如果为一个或多个模板设置了牌组覆盖选项,则卡片将转到该牌组,而不是你选择的那个。
When you import a text file, you can choose what deck to put the cards in. Keep in mind that if you have the deck override option set for one or more of your templates, the cards will go to that deck rather than the one you’ve selected.
这是一个包含三个字段的有效文件示例:
This is an example of a valid file with three fields:
apple;banana;grape
some text;other text;yet more text
有两种方法可以在字段中包含换行符或字段分隔符。
There are two ways to include newlines or the field separator in fields.
通过将字段内容置于引号中来转义字符:
Escape the characters by placing the contents of the field in quotation marks:
hello;"this is
a two line answer"
two;this is a one line field
"this includes a ; (semicolon)";another field
由于引号用于标记字段的开始和结束位置,因此如果希望将它们包含在字段中,则需要将一个双引号替换为两个双引号,以便从常规处理中“转义”它们,如下所示:
Because quotes are used to mark where a field begins and ends, if you wish to include them inside your field, you need to replace a single doublequote with two doublequotes to "escape" them from the regular handling, like so:
field one;"field two with ""escaped quotes"" inside it"
当你使用 Libreoffice 这样的电子表格程序为你创建 CSV 文件时,它会自动处理转义双引号。
When you use a spreadsheet program like Libreoffice to create the CSV file for you, it will automatically take care of escaping double quotes.
使用 HTML 新行:
Use HTML new lines:
hello; this is<br>a two line answer
two; this is a one line one
你需要在导入对话框中启用“允许在字段中使用 HTML”复选框,HTML 换行符才能工作。
You need to turn on the "allow HTML in fields" checkbox in the import dialog for HTML newlines to work.
如果你使用跨多行的挖空,转义的多行将无法正常工作。在这种情况下,请使用 HTML 换行符。
Escaped multi-lines will not work correctly if you are using cloze deletions that span multiple lines. In this case, please use HTML newlines instead.
也可以在另一个字段中包含标记,并在“导入”对话框中将其选择为标记字段:
You can also include tags in another field and select it as a tags field in the import dialog:
first field;second field;tags
这是一个有效文件的示例,其中第一行被忽略(#):
This is an example of a valid file where the first line is ignored (#):
# this is a comment and is ignored
foo bar;bar baz;baz quux
field1;field2;field3
电子表格和 UTF-8
Spreadsheets and UTF-8
如果文件中有非拉丁字符(如重音符号、日语等),Anki 希望文件以“UTF-8 编码”保存。最简单的方法是使用免费的 LibreOffice 电子表格程序而不是 Excel 来编辑文件,因为它很容易支持 UTF-8,并且可以正确导出多行内容,这与 Excel 不同。如果你想继续使用 Excel,请查看此论坛帖子以了解更多信息。
If you have non-Latin characters in your file (such as accents, Japanese and so on), Anki expects files to be saved in a 'UTF-8 encoding'. The easiest way to do this is to use the free LibreOffice spreadsheet program instead of Excel to edit your file, as it supports UTF-8 easily, and also exports multi-line content properly, unlike Excel. If you wish to keep using Excel, please see this forum post for more information.
要将电子表格保存到 Anki 可以使用 LibreOffice 读取的文件中,请转到“文件”>“另存为”,然后选择 CSV 作为文件类型。接受默认选项后,LibreOffice 将保存文件,然后你可以将保存的文件导入到 Anki 中。
To save your spreadsheet to a file Anki can read with LibreOffice, go to File>Save As, and then select CSV for the type of file. After accepting the default options, LibreOffice will save the file and you can then import the saved file into Anki.
HTML
Anki 可以将从文本文件导入的文本视为 HTML(用于网页的语言)。这意味着具有粗体、斜体和其他格式的文本可以导出到文本文件中,然后再次导入。如果要包含 HTML 格式,可以在导入时选中“允许在字段中使用 HTML”复选框。如果你试图导入内容包含尖括号或其他 HTML 语法的卡片,你可能希望关闭此功能。
Anki can treat text imported from text files as HTML (the language used for web pages). This means that text with bold, italics and other formatting can be exported to a text file and imported again. If you want to include HTML formatting, you can check the "allow HTML in fields" checkbox when importing. You may wish to turn this off if you’re trying to import cards whose content contains angle brackets or other HTML syntax.
如果你希望使用 HTML 来格式化文件,但也希望包含尖括号或符号,则可以使用以下替换项:
If you wish to use HTML for formatting your file but also wish to include angle brackets or ampersands, you may use the following replacements:
字符 | 替换 |
---|---|
< | < |
> | > |
& | & |
导入媒体资源
Importing Media
如果要包含文本文件导入中的音频和图片,请将文件复制到 collection.media 文件夹中。不要将子目录放在 media 夹中,否则某些功能将无法工作。
If you want to include audio and pictures from a text file import, copy the files into the collection.media folder. Do not put subdirectories in the media folder, or some features will not work.
复制文件后,按如下方式更改文本文件中的一个字段。
After you’ve copied the files, change one of the fields in your text file as follows.
<img src="myimage.jpg">
or
[sound:myaudio.mp3]
或者,你可以使用浏览屏幕中的查找和替换功能一次更新所有字段。如果每个字段都包含像“myaudio”这样的文本,并且你希望让它播放声音,则可以搜索(.*
)并将其替换为“[sound:\1.mp3]
”,同时启用“正则表达式”选项。
Alternatively, you can use the find and replace feature in the browse screen to update all the fields at once. If each field contains text like "myaudio", and you wish to make it play a sound, you’d search for (
.*
) and replace it with[sound:\1.mp3]
, with the 'regular expressions' option enabled.
导入带有这些引用的文本文件时,必须确保启用“允许 HTML”选项。
When importing a text file with these references, you must make sure to enable the "Allow HTML" option.
你可能会想在模板中执行此操作,例如:
You might be tempted to do this in a template, like:
<img src="{{field name}}">
Anki 不支持这一点有两个原因:搜索用过的媒体很昂贵,因为每张卡都必须渲染,而且这种功能对共享卡组用户来说并不明显。请改用查找和替换技术。
Anki doesn’t support this for two reasons: searching for used media is expensive, as each card has to be rendered, and such functionality isn’t obvious to shared deck users. Please use the find & replace technique instead.
大量媒体资源
Bulk Media
同时导入大量媒体的另一个选项是使用媒体导入插件。此加载项将自动为你选择的文件夹中的所有文件创建笔记,文件名在前面(减去文件扩展名,因此如果你有一个名为 apple.jpg 的文件,前面会显示“apple”),图像或音频在后面。如果你想要不同的媒体和文件名排列,你可以在之后更改创建的卡片的笔记模板。
Another option for importing large amounts of media at once is to use the media import add-on. This add-on will automatically create notes for all files in a folder you select, with the filenames on the front (minus the file extension, so if you have a file named apple.jpg, the front would say 'apple') and the images or audio on the back. If you would like a different arrangement of media and filenames, you can change the note type of the created cards afterwards.
添加标签
Adding Tags
如果要将“tag1”和“tag2”添加到要导入的每一行,请将以下内容添加到文本文件的顶部:
If you want to add 'tag1' and 'tag2' to every line you’re importing, add the following to the top of the text file:
tags:tag1 tag2
重复和更新
Duplicates and Updating
导入文本文件时,Anki 使用第一个字段来确定笔记是否唯一。默认情况下,如果要导入的文件的第一个字段与集合中的一个现有笔记匹配,并且该现有笔记与要导入的类型相同,则现有笔记的其他字段将根据导入文件的内容进行更新。导入屏幕中的下拉框允许你更改此行为,完全忽略重复项,或者将其作为新笔记导入,而不是更新现有笔记。
When importing text files, Anki uses the first field to determine if a note is unique. By default, if the file you are importing has a first field that matches one of the existing notes in your collection and that existing note is the same type as the type you’re importing, the existing note’s other fields will be updated based on content of the imported file. A drop-down box in the import screen allows you to change this behaviour, to either ignore duplicates completely, or import them as new notes instead of updating existing ones.
“匹配范围”设置控制如何识别重复项。当选择“笔记模板”时,如果具有相同笔记模板的另一个笔记具有相同的第一个字段,则 Anki 将识别重复的笔记。当设置为“卡片模板和牌组”时,只有当现有笔记恰好也在你要导入的牌组中时,才会标记重复的笔记。
The 'match scope' setting controls how duplicates are identified. When 'notetype' is selected, Anki will identify a duplicate if another note with the same notetype has the same first field. When set to 'notetype and deck', a duplicate will only be flagged if the existing note also happens to be in the deck you are importing into.
如果启用了更新功能,并且正在导入的笔记的旧版本已在集合中,则它们将在原地更新(在当前牌组中),而不是移动到你在导入对话框中设置的牌组中。如果笔记更新到位,则所有卡片上的现有日程安排信息都将保留。
If you have updating turned on and older versions of the notes you’re importing are already in your collection, they will be updated in place (in their current decks) rather than being moved to the deck you have set in the import dialog. If notes are updated in place, the existing scheduling information on all their cards will be preserved.
有关.apkg 文件中如何处理重复项的信息,请参阅牌组包部分。
For info on how duplicates are handled in .apkg files, please see the Deck Packages section.
文件标头
File Headers
Anki 2.1.54+支持某些可以包含在文本文件标头,使导入功能更强大或更方便。它们由#key:value
对组成,必须在文件顶部的单独行中列出,尽管标记行可能在它们之前。由于标头行以注释字符#开头,早期的 Anki 客户端将忽略它们。
Anki 2.1.54+ supports certain headers that can be included in the text file to make importing more powerful or convenient. They consist of
#key:value
pairs and must be listed in separate lines at the top of the file, though the tags line may precede them. Since header lines start with the comment character#
, earlier Anki clients will just ignore them.
你必须在首选项屏幕中启用新的导入选项,才能在 2.1.54 上使用该选项。2.1.55 中,默认为新的导入路径。
You must enable the new importing option in the preferences screen to use this on 2.1.54. On 2.1.55, the new importing path is the default.
key | 允许的值 | 行为 |
---|---|---|
separator | 逗号、分号、制表符、空格、管道、冒号或相应的文字字符 | 确定字段分隔符。 |
html | true, false | 确定是否将文件视为 HTML。 |
tags | 标签列表,用空格分隔 | 与旧语法相同。 |
columns | 名称列表,由上面设置的分隔符分隔 | 确定列的数量,并在导入时显示它们的给定名称。 |
notetype | 笔记模板名称或 id | 预设笔记模板(如果存在)。 |
deck | 牌组名称或 id | 预设牌组(如果存在)。 |
notetype column | 1, 2, 3, ... | 确定哪一列包含每个笔记的笔记模板名称或 id,请参见笔记模板列。 |
deck column | 1, 2, 3, ... | 确定哪一列包含每个笔记的牌组名称或 id,请参见牌组列。 |
tags column | 1, 2, 3, ... | 确定哪一列包含每个笔记的标记。 |
guid column | 1, 2, 3, ... | 确定哪一列包含每个笔记的 GUID,请参阅 GUID 列。 |
笔记模板列
Notetype Column
通常,文件中的所有笔记都将映射到单个笔记模板,你可以选择将哪一列映射到该笔记模板的哪个字段。
Usually, all notes from a file will be mapped to a single notetype, and you may choose which column should be mapped to which field of that notetype.
如果有一列具有笔记模板名称或 id,则情况会发生变化。这允许导入具有不同笔记模板的笔记,并且它们的字段将被隐式映射:第一个正则列用于任何笔记的第一个字段,而不管其笔记模板如何,第二个正则列则用于第二个字段,依此类推。这里的“正则列”是指不包含特殊信息(如牌组、标签、笔记模板或 GUID)的列。
That changes, if there is a column with notetype names or ids. This allows to import notes with different notetypes, and their fields will be mapped implicitly: The first regular column is used for the first field of any note regardless of its notetype, the second regular column for the second field, and so on. A 'regular column' here being a column that does not contain special information like decks, tags, notetypes or GUIDs.
牌组列
Deck Column
通常,由于导入文本文件而创建的任何新卡片都将放置在你选择的一副牌组中。但是,如果文件包含一个牌组列,则新的笔记卡片将被放置在其指定的牌组中。如果牌组不存在,将创建具有给定名称的牌组。
Usually, any new cards created as a result of importing a text file will be placed in a single deck of your choice. If the file contains a deck column, however, new cards of a note will be placed in its specified deck instead. If the deck does not exist, a deck with the given name will be created.
GUID 列
GUID Column
GUID 代表全局唯一标识符。当你在 Anki 中创建笔记时,Anki 会为每个笔记分配一个唯一的 ID,该 ID 可用于重复检查。如果导出包含 GUID 的笔记,则可以对笔记进行更改,只要不修改 GUID 字段,就可以将笔记导入以更新现有笔记。
GUID stands for Globally Unique Identifier. When you create notes in Anki, Anki assigns each note a unique ID, which can be used for duplicate checking. If you export your notes with the GUID included, you can make changes to the notes, and as long as you do not modify the GUID field, you'll be able to import the notes back in to update the existing notes.
请注意,GUID 是由 Anki 创建的。如果你正在创建自己的 ID,例如 MYNOTE0001,则建议将 ID 放置在第一个字段中,而不是将它们分配给 Anki 的内部 GUID。导入时,Anki 也可以使用第一个字段进行重复检查,因此你不需要将 ID 设置为 GUID 即可更新笔记。
Please note that the GUID is intended to be created by Anki. If you are creating your own IDs, such as MYNOTE0001, then it's recommended that you place the IDs in the first field, instead of assigning them to Anki's internal GUID. When importing, Anki is able to use the first field for duplicate checking as well, so you do not need to make IDs a GUID in order to be able to update your notes.