-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP - Document the way to write reader and writer plugins (#91)
* 📚 add custom plugin writer * This is an auto-commit, updating project meta data, such as changelog.rst, contributors.rst * 📚 update writer plugin * 📚 update plugin writer and reader documentation * 📚 telling the location of the example codes Co-authored-by: chfw <chfw@users.noreply.github.com>
- Loading branch information
Showing
10 changed files
with
180 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,7 @@ get_data(.., library='pyexcel-ods') | |
csvz | ||
sqlalchemy | ||
django | ||
options | ||
extensions | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,6 +193,7 @@ get_data(.., library='pyexcel-ods') | |
csvz | ||
sqlalchemy | ||
django | ||
options | ||
extensions | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import yaml | ||
from pyexcel_io import save_data | ||
from pyexcel_io.plugins import IOPluginInfoChainV2 | ||
from pyexcel_io.plugin_api import IWriter, ISheetWriter | ||
|
||
|
||
class MySheetWriter(ISheetWriter): | ||
def __init__(self, sheet_reference): | ||
self.native_sheet = sheet_reference | ||
|
||
def write_row(self, data_row): | ||
self.native_sheet.append(data_row) | ||
|
||
def close(self): | ||
pass | ||
|
||
|
||
class MyWriter(IWriter): | ||
def __init__(self, file_name, file_type, **keywords): | ||
self.file_name = file_name | ||
self.content = {} | ||
|
||
def create_sheet(self, name): | ||
array = [] | ||
self.content[name] = array | ||
return MySheetWriter(array) | ||
|
||
def close(self): | ||
with open(self.file_name, "w") as f: | ||
f.write(yaml.dump(self.content, default_flow_style=False)) | ||
|
||
|
||
IOPluginInfoChainV2(__name__).add_a_writer( | ||
relative_plugin_class_path="MyWriter", | ||
locations=["file"], | ||
file_types=["yaml"], | ||
stream_type="text", | ||
) | ||
|
||
if __name__ == "__main__": | ||
data_dict = { | ||
"sheet 1": [[1, 3, 4], [2, 4, 9]], | ||
"sheet 2": [["B", "C", "D"]], | ||
} | ||
|
||
save_data("mytest.yaml", data_dict) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters