Git Product home page Git Product logo

pptx-template's Introduction

pptx-template Build Status

Overview

pptx-template is a PowerPoint presentation builder.

This helps your routine reporting work that have many manual copy-paste from excel chart to powerpoint, or so.

  • Building a new powerpoint presentation file from a "template" pptx file which contains "id"
  • Import some strings and CSV data which is defined in a JSON config file or a Python dict
  • "id" in pptx template is expressed as a tiny DSL, like "{sales.0.june.us}"
  • requires python envirionment (3), pandas, python-pptx
  • for now, only UTF-8 encoding is supported for json, csv

Text substitution

CSV Import

Getting started

TBD

$ pip install pptx-template
$ echo '{ "slides": [ { "greeting" : "Hello!!" } ] }' > model.json

# prepare your template file (test.pptx) which contains "{greeting}" in somewhere

$ pptx-template --out out.pptx --template test.pptx --model model.json

Development

Installation

Install using pyenv

git clone https://github.com/m3dev/pptx-template.git

pyenv install 3.7.1 # Install Python
pyenv shell 3.7.1 # Create Python shell

venv .venv # Create virtual environment for development
source .venv/bin/activate # Use the virtual environment for development

python setup.py develop         # Setup egg-info folder for development & Install dependencies
pip install -r requirements.txt # Install dependencies

Run with REPL - Use this for development

Launch the Python REPL client

cd {project folder}
pyenv shell 3.7.1
python

Run the following with the Python REPL

import sys
from importlib import reload
import pptx_template.cli as cli


## Argument Settings
## sys.argv = ['{filename.py}', '--out', '{file/path/output.pptx}', '--template', '{file/path/template.pptx}', '--model', '{file/path/data.xlsx}', '--debug']
## Following is an example with test files
sys.argv = ['dummy.py', '--out', 'test/data3/out.pptx', '--template', 'test/data3/in.pptx', '--model', 'test/data3/in.xlsx', '--debug']

## Run the program
cli.main()

## Run the following after modifying the source code
reload(sys.modules.get('pptx_template.xlsx_model'))
reload(sys.modules.get('pptx_template.text'))
reload(sys.modules.get('pptx_template.table'))
reload(sys.modules.get('pptx_template.chart'))
reload(sys.modules.get('pptx_template.core'))
reload(sys.modules.get('pptx_template.cli'))
cli.main()

Run via CLI

## pptx_template --out {file/path/output.pptx} --template {file/path/template.pptx} --model {file/path/data.xlsx}  --debug
pptx_template --out test/data3/out.pptx --template test/data3/in.pptx --model test/data3/in.xlsx  --debug

Run Tests

pytest

Deployment Process

  1. Create a feature branch
  2. Implement the new feature
  3. Test with all versions of Python
  4. Push changes to the feature branch
  5. Create a Pull Request on Github
  6. Request a code review
  7. Verify QA(If you want to verify QA、build the source in your local environment)
  8. Merge Pull Request
  9. Upload to PyPI(Only for PyPI repository administrators)

Upload to PyPI

  1. Install packages needed for uploading to PyPI
pip install wheel
pip install twine
  1. Compile
python setup.py bdist_wheel
  1. Upload to PyPI
twine upload dist/*

pptx-template's People

Contributors

doloopwhile avatar pjbollinger avatar reki2000 avatar rinoguchi avatar skar404 avatar sptea avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pptx-template's Issues

XY-chart doesn't handle CSV properly

for general business reports, multi-series XY chart should handle csv data as

Y, X1, X2, ...
0, 10, 20, ...
1, 20, 30, ...

instead of

Y0, X0, Y1, X1, ...
40, 10,  1, 20, ...
30, 20,  4, 15, ...

proposed fix:

def _build_xy_chart_data(csv):
  chart_data = XyChartData()
  for i in range(1, csv.columns.size):
    series = chart_data.add_series(csv.columns[i])
    xy_col = csv.ix[:, [0, i]]
    for (_, row) in xy_col.iterrows():
      log.debug(u"adding xy %d,%d" % (row[1], row[0]))
      series.add_data_point(row[1], row[0])
  return chart_data

table: fill cells with csv data

if ID in table object refers a csv-setting (not a plaitn string), its CSV data will be inserted into the table, where it's top left position is the cell that the ID is written.

for example,

pptx:
+---------+-----+
| {data}  |     |
+---------+-----+
|         |     |
+---------+-----+

model:
{
  "data" : {
     "file_name": "data1.csv"  // contains " X,Y [LF]  10,100"
  }
}

will be like:

+---------+-----+
| X       |  Y  |
+---------+-----+
|      10 | 100 |
+---------+-----+

Remove all slides which contain "id" text-frames

Problem

For pptx-template cannot copy/create new slide, we have to prepare all variations of slides in templates. After we picked up one of them to use, we should remove all unused slides. But API only supports deleting one slide by id. This requires us to maintain which ids are used and which are unused.

Solution

When we pick up one slide for editing, we will delete id text-frame at the same time. If new feature will remove all slides which contains "id" frame, which means the slide has not been used any more, we don't have to know which are unused.

Support TSV

Problem

CSV is not easy to handle, because always we are suffered from "What if a column includes comma or double-quote ?" problem, especially for report generating scripts.

Solution

TSV base data handling. pptx-template should handle TSV.

Specification

When file-name is ended with '.tsv', let pandas to load file as TSV.

If file name for id "chart1" is not provided, try to check id1.csv then id1.tsv

Fix classifiers in setup.{py,cfg}

Python 2 is given. However, Python 2 is no longer supported by pptx-template.

classifiers =
  Development Status :: 3 - Alpha
  Topic :: Utilities
  Programming Language :: Python :: 2
  Programming Language :: Python :: 2.7

Todos for this project

  • Unify readme.rst and readme.md
  • Write a document for JSON configuration file
  • Automate release operation (tagging, bump version, github push, PyPI push)
  • Rewrite all source code comments in English
  • Add --version option

Settings to be applied to all slides

Problem

If all slides have the same string like "Created date: 2017-10-20", model.json should have the same setting on EVERY slide settings.

Solution

Introduce "global" setting into model.json

Specification

The same settings for each slides, but written under "global" key in JSON.

If a key in "slides" setting has the same name with the key defined in "global", the value defined in "slides" is used.

{
  "global": {
     "<key1>": "<value1>",
     "<key2>": { <chart settings> }
  },
  "slides": {
     "<slide_id>": {
        "<key1>": "<value1_local>",       # this value is used instead of <value1> in global
       ....
     }
  }

ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters

Recently I received this error. Do you know how to debug/fix it? I don't see any problems with my data's text.

Traceback (most recent call last):"," File \"\/usr\/local\/bin\/pptx_template\", line 11, in <module>"," load_entry_point('pptx-template==0.2.9', 'console_scripts', 'pptx_template')()"," File \"\/usr\/local\/lib\/python3.6\/site-packages\/pptx_template-0.2.9-py3.6.egg\/pptx_template\/cli.py\", line 75, in main"," File \"\/usr\/local\/lib\/python3.6\/site-packages\/pptx_template-0.2.9-py3.6.egg\/pptx_template\/cli.py\", line 36, in process_all_slides"," File \"\/usr\/local\/lib\/python3.6\/site-packages\/pptx_template-0.2.9-py3.6.egg\/pptx_template\/cli.py\", line 27, in process_one_slide"," File \"\/usr\/local\/lib\/python3.6\/site-packages\/pptx_template-0.2.9-py3.6.egg\/pptx_template\/core.py\", line 45, in edit_slide"," File \"\/usr\/local\/lib\/python3.6\/site-packages\/pptx_template-0.2.9-py3.6.egg\/pptx_template\/styled_text.py\", line 39, in replace_all_els_in_table"," File \"\/usr\/local\/lib\/python3.6\/site-packages\/pptx_template-0.2.9-py3.6.egg\/pptx_template\/styled_text.py\", line 94, in replace_all_els_in_text_frame"," File \"\/usr\/local\/lib\/python3.6\/site-packages\/pptx_template-0.2.9-py3.6.egg\/pptx_template\/styled_text.py\", line 61, in replace_el_in_text_frame_with_list"," File \"\/usr\/local\/lib\/python3.6\/site-packages\/pptx_template-0.2.9-py3.6.egg\/pptx_template\/styled_text.py\", line 136, in _insert_styled_run"," File \"\/usr\/local\/lib\/python3.6\/site-packages\/python_pptx-0.6.17-py3.6.egg\/pptx\/text\/text.py\", line 688, in text"," self._r.t.text = to_unicode(str)"," File \"src\/lxml\/etree.pyx\", line 1024, in lxml.etree._Element.text.__set__"," File \"src\/lxml\/apihelpers.pxi\", line 747, in lxml.etree._setNodeText"," File \"src\/lxml\/apihelpers.pxi\", line 735, in lxml.etree._createTextNode"," File \"src\/lxml\/apihelpers.pxi\", line 1540, in lxml.etree._utf8","ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters"

IO Error on python 2 when chart CSV includes UTF-8 character

on Python 2.7 environment, python setup.py test failed with:

======================================================================
ERROR: test_simple (test.cliTest.MyTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\me\git\pptx-template\test\cliTest.py", line 12, in test_simple
    main()
  File "c:\me\git\pptx-template\pptx_template\cli.py", line 53, in main
    process_slide(ppt, slide, model)
  File "c:\me\git\pptx-template\pptx_template\cli.py", line 20, in process_slide
    edit_slide(slide, model)
  File "c:\me\git\pptx-template\pptx_template\core.py", line 40, in edit_slide
    ch.load_data_into_chart(chart, model)
  File "c:\me\git\pptx-template\pptx_template\chart.py", line 98, in load_data_into_chart
    replace_chart_data_with_csv(chart, chart_id, chart_setting)
  File "c:\me\git\pptx-template\pptx_template\chart.py", line 74, in replace_chart_data_with_csv
    chart_data = _build_chart_data(csv)
  File "c:\me\git\pptx-template\pptx_template\chart.py", line 36, in _build_chart_data
    log.debug(u"adding series %s" % (col.name))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 0: ordinal not in range(128)

----------------------------------------------------------------------

Invalid value for table

Invalid value table

Code:

ppt = Presentation('in.pptx')
process_all_slides({
        "0": "remove",
        "1": {
            "greeting": {
                "en": "Hello!",
                "ja": "こんにちは!"
            },
            "season": ["Spring", "Summer", "Autumn", "Winter"]
        },
        "2": {
            "bars": {
                "file_name": "chart1.csv",
                "value_axis_max": 150,
                "value_axis_min": 50
            }
        },
        "3": {
            "xy": {}
        },
        "4": {
            "chart": {
                "body": "Season,売り上げ,利益,利益率\n春,100,50,0.5\n夏,110,60,0.5\n秋,120,70,0.5\n冬,130,80,0.6",
                "value_axis_max": 150,
                "value_axis_min": 50
            }
        },
        "5": {
            "table": {
                "body": "Season,売り上げ,利益,利益率\n春,100,50,0.5\n夏,110,60,0.5\n秋,120,70,0.5\n冬,130,80,0.6"
            }
        },
        "pie": {
            "segment": {}
        },
        "nan": {
            "bars": {
                "body": "Season,売り上げ,利益,\n春,100,50,0.5\n,110,60,0.5\n秋,120,70,0.5\n冬,130,80,0.6",
                "value_axis_max": 150,
                "value_axis_min": 50
            }
        }
    }, ppt, True)
ppt.save('out.pptx')

Error:

Invalid value for {table}, model: {'body': 'Season,売り上げ,利益,利益率\n春,100,50,0.5\n夏,110,60,0.5\n秋,120,70,0.5\n冬,130,80,0.6'}

2018-01-23 14 42 06

More style-break-free text substitution

For mixed style text, to keep an EL {....} to be one "run" structure is very frustrating work.

How about handle EL which is divided into some "run"s like

run[0].text = 'Hello, {'
run[1].text = 'contry'
run[2].text = '} !!'

with the key 'contry' has value "World",

to

run[0].text = 'Hello, World'
run[1].text = ''
run[2].text = '!!'

Improve README.md

README.md now includes both Japanese and English text (and each contents differs).

It should be

  • English text only
    or
  • Devided to files and contents be equal

Write import settings in Excel

Problem

Sometimes we want to make pptx report from exsisting Excel sheet, which contains many source data in several sheets. When using pptx-template, we should make JSON, but it will be another routine work.

Solution

Introduce "excel model mode" which enables writing all settings in special sheet

Specification

Excel sheet for confituration

The workbook should have a special sheet named "model".

This sheet includes configuration data like:

slide_id     EL        value              range_name
-------------------------------------------------------
p01          title.us  Hello
p01          title.jp  こんにちは
p01          chart                        <excel_range_name>

command-line and its output

$ generate_model foobar.xls

creates

  • p01_chart.tsv
  • model.json
{ 
  "slides" {
    "p01": {
       "title" : {
          "us" : "Hello"
          "jp" : "こんにちは"
       },
       "chart": {
          "file_name": "p01_chart.tsv"  # this file is filled with the data from <range_name>
       }
  }
}

pick up CSV data from excel book

This tool requires data to be CSV format, but when people creates data on excel, to convert it into CSV format will be another routine task.

Introduce new csv setting as:

{
  "data": {
    "excel": { "file_name": "foobar.xlsx", "sheet": "sheet1", "range": "A1:Z99" }
  }
}

filter csv data

To share the same CSV file for some segment-wise charts, It's useful to have a filtering feature:

  "chart": {
    "file_name": "data-1.csv",
    "filter": { "equals": { "year": "2002" } }  <-- this means "only use rows which has a value "2002" at "year" column
  }

otherwise, users should divide a CSV file into segment-wise CSV files. It makes CSV file handing work more messy and error prone.

Jupyter pptx-template padas

hi,

I have a serious issue while i try to install pptx-template in Jupyter .

My configuration
Windows 10, Jupyter the last realese of Anaconda3 202105 (64)

Some thing crash with the requirement Pandas pandas<=0.24.0,>=0.22.0

  • windows sdk 10

  • Visual studio C++ install

  • Why this requirement pandas<=0.24.0,>=0.22.0 ?

have you any idea.

Thanks
( sorry 4 my english)

[Improvement] use Jinja2 templating scheme

Hi, thank you for your work, this is indeed VERY helpful.

This could be great to turn tempalting scheme into Jinja2 one (http://jinja.pocoo.org/docs/2.10/)

The best feature could be case control and iteration with Jinja, just like (in a PPTX file) :


----
Here are the list of to-dos : 

{% for entry in hello.entries %}
-  TODO: {{entry}}
{%endfor%}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.