Skip to content

Commit

Permalink
DOC: Expose ExcelWriter as part of the Generated API (#22359)
Browse files Browse the repository at this point in the history
  • Loading branch information
newinh authored and jreback committed Sep 18, 2018
1 parent d39249a commit c44581f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
6 changes: 6 additions & 0 deletions doc/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ Excel
read_excel
ExcelFile.parse

.. autosummary::
:toctree: generated/
:template: autosummary/class_without_autosummary.rst

ExcelWriter

JSON
~~~~

Expand Down
14 changes: 10 additions & 4 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1979,11 +1979,17 @@ def _repr_latex_(self):
If you wish to write to more than one sheet in the workbook, it is
necessary to specify an ExcelWriter object:
>>> writer = pd.ExcelWriter('output2.xlsx', engine='xlsxwriter')
>>> df1.to_excel(writer, sheet_name='Sheet1')
>>> df2 = df1.copy()
>>> df2.to_excel(writer, sheet_name='Sheet2')
>>> writer.save()
>>> with pd.ExcelWriter('output.xlsx') as writer:
... df1.to_excel(writer, sheet_name='Sheet_name_1')
... df2.to_excel(writer, sheet_name='Sheet_name_2')
To set the library that is used to write the Excel file,
you can pass the `engine` keyword (the default engine is
automatically chosen depending on the file extension):
>>> df1.to_excel('output1.xlsx', engine='xlsxwriter')
"""

def to_json(self, path_or_buf=None, orient=None, date_format=None,
Expand Down
35 changes: 35 additions & 0 deletions pandas/io/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,8 +824,43 @@ class ExcelWriter(object):
Notes
-----
None of the methods and properties are considered public.
For compatibility with CSV writers, ExcelWriter serializes lists
and dicts to strings before writing.
Examples
--------
Default usage:
>>> with ExcelWriter('path_to_file.xlsx') as writer:
... df.to_excel(writer)
To write to separate sheets in a single file:
>>> with ExcelWriter('path_to_file.xlsx') as writer:
... df1.to_excel(writer, sheet_name='Sheet1')
... df2.to_excel(writer, sheet_name='Sheet2')
You can set the date format or datetime format:
>>> with ExcelWriter('path_to_file.xlsx',
date_format='YYYY-MM-DD',
datetime_format='YYYY-MM-DD HH:MM:SS') as writer:
... df.to_excel(writer)
You can also append to an existing Excel file:
>>> with ExcelWriter('path_to_file.xlsx', mode='a') as writer:
... df.to_excel(writer, sheet_name='Sheet3')
Attributes
----------
None
Methods
-------
None
"""
# Defining an ExcelWriter implementation (see abstract methods for more...)

Expand Down

0 comments on commit c44581f

Please sign in to comment.