Skip to content

Commit 4ac04e1

Browse files
committed
📚 more translations
1 parent 15fd52e commit 4ac04e1

File tree

1 file changed

+48
-41
lines changed

1 file changed

+48
-41
lines changed

docs/source/index.rst

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,16 @@ python 版本,请继续使用 0.5.x 。
170170
171171
既然有了 pyexcel , 为什么我还要装 django-excel ?
172172

173-
#. **加快上传文件处理速度**. **django-excel** 通过 ExcelMemoryFileUploadHandler 和 TemporaryExcelFileU
174-
ploadHandler 让你直接处理上传的文件。 MemoryFileUploadHandler 把上传的文件存在内存里,这样呢 django-excel
175-
可以直接从内存读取上传文件。 TemporaryExcelFileUploadHandler 呢,是把上传文件存在临时文件中,django-excel
176-
则是直接读临时文件。到底是哪个类被 Django 调用呢?是有 FILE_UPLOAD_MAX_MEMORY_SIZE 决定的。如果上传
177-
文件小于这个最大值,那么 django 会把上传文件存在内存里。否则,就存在临时文件里。
173+
#. **加快上传文件处理速度**. **django-excel** 通过 ExcelMemoryFileUploadHandler 和
174+
TemporaryExcelFileUploadHandler 让你直接处理上传的文件。
175+
ExcelemoryFileUploadHandler 把上传的文件存在内存里,这样呢 django-excel 可以直接从内
176+
存读取上传文件。 TemporaryExcelFileUploadHandler 呢,是把上传文件存在临时文件中,
177+
django-excel 则是直接读临时文件。到底是哪个类被 Django 调用呢?
178+
是由 FILE_UPLOAD_MAX_MEMORY_SIZE 决定的。如果上传文件小于这个最大值,
179+
那么 Django 会把上传文件存在内存里。否则,就存在临时文件里。
178180

179-
#. **直接把上传数据存入数据库**. **django-excel** 用批量方式( bulk_insert )把你的数据导入你的 django model.
181+
#. **直接把上传数据存入数据库**. **django-excel** 用批量方式( bulk_insert )
182+
把你的数据导入你的 Django model.
180183

181184

182185
安装
@@ -202,8 +205,8 @@ python 版本,请继续使用 0.5.x 。
202205

203206
$ pip install pyexcel-xlsx
204207

205-
一反 Django 开箱即用的理念,django-excel 需要开发人员自己选择所需 pyexcel 的套件。主要原因是,
206-
第三方软件 xlwt, openpyxl, odfpy 也是会拉长下载速度和占用磁盘空间。
208+
一反 Django 开箱即用的理念,django-excel 需要开发人员自己选择所需 pyexcel 的套件。
209+
主要原因是,第三方软件 xlwt, openpyxl, odfpy 也是会拉长下载速度和占用磁盘空间。
207210

208211
配置
209212
------------------------
@@ -245,7 +248,8 @@ You will need to update your *settings.py*:
245248

246249
git clone https://github.com/pyexcel/django-excel.git
247250

248-
整个测试项目是按照 Django 的指南的第 `<https://docs.djangoproject.com/en/1.11/intro/tutorial01/>`_,
251+
整个测试项目是按照 Django 的指南的第
252+
`<https://docs.djangoproject.com/en/1.11/intro/tutorial01/>`_,
249253
`<https://docs.djangoproject.com/en/1.11/intro/tutorial02/>`_,
250254
`<https://docs.djangoproject.com/en/1.11/intro/tutorial03/>`_ 部分写的。
251255
所以,作者就不最述了。如果大家想自己从零开始呢,请移步到 Django 指南,做完第三部分,再回来。
@@ -297,7 +301,7 @@ http://localhost:8000/polls/, 你应该可以看到下面这个上传表格:
297301
:lines: 14-36
298302

299303

300-
**UploadFileForm** 是 django 的一个文件上传模块。然后往下看 **filehandle**.
304+
**UploadFileForm** 是 Django 的一个文件上传模块。然后往下看 **filehandle**.
301305
它可能是 ExcelInMemoryUploadedFile
302306
或是 TemporaryUploadedExcelFile。它们两个都继承了 ExcelMixin, 所以它们都又有
303307
以下的函数,比如 get_sheet, get_array 。
@@ -313,8 +317,8 @@ http://localhost:8000/polls/, 你应该可以看到下面这个上传表格:
313317
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
314318

315319
这个例子展示如何把上传的 excel 的内容直接输入数据库。
316-
`sample-data.xls <https://github.com/pyexcel/django-excel/blob/master/sample-data.xls>`_ 是我们
317-
样上传的文件
320+
`sample-data.xls <https://github.com/pyexcel/django-excel/blob/master/sample-data.xls>`_
321+
是我们要上传的文件
318322

319323
.. pyexcel-table:: ../../sample-data.xls
320324

@@ -358,14 +362,15 @@ http://localhost:8000/polls/, 你应该可以看到下面这个上传表格:
358362

359363
你可以用管理员界面不数据都删了,再重复上传一次。
360364

361-
现在,我们来读一下源代码 `polls/views.py <https://github.com/pyexcel/django-excel/blob/master/polls/views.py#L79>`_
365+
现在,我们来读一下源代码
366+
`polls/views.py <https://github.com/pyexcel/django-excel/blob/master/polls/views.py#L79>`_
362367
请关注这部分代码:
363368

364369
.. literalinclude:: ../../polls/views.py
365370
:lines: 72-92
366371

367372
把上传的 excel 存入数据库的功臣是 :meth:`~django_excel.save_book_to_database`.
368-
函数变量 **models** 是 django model 数组; **initializers** 是与之对应的初始化函数。
373+
函数变量 **models** 是 Django model 数组; **initializers** 是与之对应的初始化函数。
369374
在代码中,你会注意到,作者没有给 Question 写初始化函数,所以就给了 None;但是把 `choice_func`
370375
给了 Choice。**mapdicts** 是一个用来控制数列栏名字的数组。 它的成员可以是一个数组,也
371376
可以是一个字典::
@@ -404,24 +409,26 @@ http://localhost:8000/polls/export/book,这次呢,一个下载对话框直
404409
:meth:`~django_excel.make_response_from_tables` 其实做了所有的事情: 读取数据,
405410
把它们转换成 xls,再发给浏览器。做为开发人员,你需要给出要输出的表和 excel 文件类型。
406411

407-
与此同时,你还可打开另外一个链接: http://localhost:8000/polls/export/sheet 。它会把 **Question**
408-
输出成一个单页的表格文件。
412+
与此同时,你还可打开另外一个链接: http://localhost:8000/polls/export/sheet 。
413+
它会把 **Question** 输出成一个单页的表格文件。
409414

410415

411416
直接把 excel 文件渲染成 excel 的样子
412417
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
413418

414-
最开始已经出现了这个渲染的形式。首先呢,`handsontable 开发人员 <https://handsontable.com/>`_ 做了
419+
最开始已经出现了这个渲染的形式。首先呢,
420+
`handsontable 开发人员 <https://handsontable.com/>`_ 做了
415421
所有的工作。其次 `pyexcel-handsontable`_ 仅仅做了集成而已。 想要用这个的话,你需要自己装::
416422

417423
$ pip install pyexcel-handsontable
418424

419-
现在,我们看看这个是如何调用的。简单地说,就是把输出的文件后最写成: 'handsontable.html' 就可以了。
425+
现在,我们看看这个是如何调用的。简单地说,就是把输出的文件后最写成: 'handsontable.html'
426+
就可以了。
420427

421428
.. literalinclude:: ../../polls/views.py
422429
:lines: 153-155
423430

424-
你可以把 handontable 文件嵌入 django 的模版里面。下面是所需的代码:
431+
你可以把 handontable 文件嵌入 Django 的模版里面。下面是所需的代码:
425432

426433
.. literalinclude:: ../../polls/views.py
427434
:lines: 158-189
@@ -439,16 +446,17 @@ and http://localhost:8000/polls/embedded_handson_view_single/.
439446

440447
前面讲了如何把一个多表格的 excel 文件里的数据输入数据库。 现在我们看看输入一个表格。
441448
打开这个链接:http://localhost:8000/polls/imports_sheet/, w
442-
这次上传 `sample-sheet.xls <https://github.com/pyexcel/django-excel/blob/master/sample-sheet.xls>`_
443-
然后 django 管理员界面可以查看是否有收到数据。
449+
这次上传
450+
`sample-sheet.xls <https://github.com/pyexcel/django-excel/blob/master/sample-sheet.xls>`_
451+
然后 Django 管理员界面可以查看是否有收到数据。
444452

445453
下面我们来读代码:
446454

447455
.. literalinclude:: ../../polls/views.py
448456
:lines: 104-116
449457

450458
因为是单个表格,所以我们给一个 mapdict 参数并调用
451-
:meth:`~django_excel.ExcelMixin.save_to_database` 来存到一个 django 模型里。
459+
:meth:`~django_excel.ExcelMixin.save_to_database` 来存到一个 Django 模型里。
452460

453461
看到了多了一个参数 'name_columns_by_row' 吗?为什么需要它?
454462
是这样的,一般来讲,如果你的表格的第一行是栏目名字呢,你就不需要它。
@@ -474,15 +482,14 @@ and http://localhost:8000/polls/embedded_handson_view_single/.
474482
`这部分 pyexcel-io 的代码 <https://github.com/pyexcel/pyexcel-io/blob/master/pyexcel_io/djangobook.py#L98>`_,
475483
和 `django-excel 问题 2 <https://github.com/pyexcel/django-excel/issues/2>`_
476484

477-
为了除去这个警告呢,你需要在 django 的管理员界面清空所有数据。然后再试一下。
485+
为了除去这个警告呢,你需要在 Django 的管理员界面清空所有数据。然后再试一下。
478486

479487

480488
如果 excel 数据里有一些与数据库数据重叠了,怎么办?
481489
********************************************************************************
482490

483491
你可以提供自己的一个初始化函数。这个数在遇到重叠的数据的时候,返回 None 这样 django-excel
484-
就会跳过当前的一行数据。
485-
当然,在初始化函数里,你也可以更新数据库。最重要的是,只有你的初始化函数返回 None,
492+
就会跳过当前的一行数据。当然,在初始化函数里,你也可以更新数据库。最重要的是,只有你的初始化函数返回 None,
486493
django-excel 会尽量用批量输入,而不是一个一个输入数据库。
487494

488495

@@ -503,7 +510,7 @@ django-excel 会尽量用批量输入,而不是一个一个输入数据库。
503510
渲染你的数据
504511
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
505512

506-
为了渲染数据,我们先去 django 的管理员界面,增加一些投票。
513+
为了渲染数据,我们先去 Django 的管理员界面,增加一些投票。
507514

508515
.. image:: admin-vote.png
509516

@@ -572,47 +579,47 @@ a little bit more time in coding, documentation and writing interesting posts.
572579
函数参考
573580
---------------
574581

575-
**django-excel** attaches **pyexcel** functions to **InMemoryUploadedFile** and **TemporaryUploadedFile**. Hence, the following functions are available for the uploaded files, e.g. request.FILES['your_uploaded_file'].
582+
**django-excel** 把 **pyexcel** 的函数嫁接到了 **InMemoryUploadedFile** 和 **TemporaryUploadedFile**。所以,以下的函数
583+
都会出现在上载文件的实例里: request.FILES['your_uploaded_file'] 。
576584

577585
.. module:: django_excel.ExcelMixin
578586

579587
.. method:: get_sheet(sheet_name=None, **keywords)
580588

581-
:param sheet_name: For an excel book, there could be multiple sheets. If it is left
582-
unspecified, the sheet at index 0 is loaded. For 'csv', 'tsv' file,
583-
*sheet_name* should be None anyway.
584-
:param keywords: additional keywords to :meth:`pyexcel.get_sheet`
585-
:returns: A sheet object
589+
:param sheet_name: 对于多个表单的 excel 文件,它可以用来指定从哪一个表单取数据。缺省值是第一个表单。
590+
要是 csv , tsv 文件的话,可以忽略 *sheet_name* 。
591+
:param keywords: 其他 :meth:`pyexcel.get_sheet` 的参数
592+
:returns: :class:`pyexcel.Sheet`
586593

587594
.. method:: get_array(sheet_name=None, **keywords)
588595

589-
:param sheet_name: same as :meth:`~django_excel.ExcelMixin.get_sheet`
590-
:param keywords: additional keywords to pyexcel library
591-
:returns: a two dimensional array, a list of lists
596+
:param sheet_name: 和前面 :meth:`~django_excel.ExcelMixin.get_sheet` 一样。
597+
:param keywords: 其他 :meth:`pyexcel.get_array` 的参数
598+
:returns: 二维数组(a list of lists
592599

593600
.. method:: iget_array(sheet_name=None, **keywords)
594601

595-
:param sheet_name: same as :meth:`~django_excel.ExcelMixin.get_sheet`
596-
:param keywords: additional keywords to pyexcel library
597-
:returns: a generator for a two dimensional array, a list of lists
602+
:param sheet_name: 和前面 :meth:`~django_excel.ExcelMixin.get_sheet` 一样。
603+
:param keywords: 其他 :meth:`pyexcel.iget_array` 的参数
604+
:returns: 数组产生器
598605

599606
.. method:: get_dict(sheet_name=None, name_columns_by_row=0, **keywords)
600607

601-
:param sheet_name: same as :meth:`~django_excel.ExcelMixin.get_sheet`
608+
:param sheet_name: 和前面 :meth:`~django_excel.ExcelMixin.get_sheet` 一样。
602609
:param name_columns_by_row: uses the first row of the sheet to be column headers by default.
603610
:param keywords: additional keywords to pyexcel library
604611
:returns: a dictionary of the file content
605612

606613
.. method:: get_records(sheet_name=None, name_columns_by_row=0, **keywords)
607614

608-
:param sheet_name: same as :meth:`~django_excel.ExcelMixin.get_sheet`
615+
:param sheet_name: 和前面 :meth:`~django_excel.ExcelMixin.get_sheet` 一样。
609616
:param name_columns_by_row: uses the first row of the sheet to be record field names by default.
610617
:param keywords: additional keywords to pyexcel library
611618
:returns: a list of dictionary of the file content
612619

613620
.. method:: iget_records(sheet_name=None, name_columns_by_row=0, **keywords)
614621

615-
:param sheet_name: same as :meth:`~django_excel.ExcelMixin.get_sheet`
622+
:param sheet_name: 和前面 :meth:`~django_excel.ExcelMixin.get_sheet` 一样。
616623
:param name_columns_by_row: uses the first row of the sheet to be record field names by default.
617624
:param keywords: additional keywords to pyexcel library
618625
:returns: a generator for a list of dictionary of the file content

0 commit comments

Comments
 (0)