Code Monkey home page Code Monkey logo

pyexcel-xlsxwx's Introduction

pyexcel-xlsxwx

Github Actions PyPI version shields.io PyPI license PyPI pyversions

Save pyexcel data with XlsxWriter, while retaining good formatting.

Features

  • Allow setting column widths and word wrap.
  • A package for reading data is not included, please see pyexcel's plugins here.

Installation

$ pip install pyexcel-xlsxwx

Usage

>>> import pyexcel_xlsxwx
>>> data = OrderedDict() # from collections import OrderedDict
>>> data.update({"Sheet 1": [[1, 2, 3], [4, 5, 6]]})
>>> data.update({"Sheet 2": [["row 1", "row 2", "row 3"]]})
>>> pyexcel_xlsxwx.save_data("your_file.xlsx", data)

You can also define a custom config via:

>>> pyexcel_xlsxwx.save_data("your_file.xlsx", data, config=config)

Where config can be dictionary or path to YAML file.

The default YAML config is:

workbook:
  constant_memory: true
  strings_to_numbers: false
  strings_to_formulas: false
  strings_to_urls: true
worksheet:
  _default:
    freeze_panes: A2
#    column_width: 30
    smart_fit: true
    max_column_width: 30
format:
  _default:
    valign: top
    text_wrap: true

column_width can also accept a list and a dictionary where key indicates the column.

row_height can also be set the same way.

To cancel out freeze_panes, try:

>>> pyexcel_xlsxwx.save_data("your_file.xlsx", data, config={'worksheet': {'_default': {'freeze_panes': None}}})

The settings will merge (thanks to https://stackoverflow.com/questions/20656135/python-deep-merge-dictionary-data), so that the other formattings won't be lost.

Related projects

  • pyexcel-openpyxlx - export the styles for XlsxWriter.
  • pyexcel-export - operates using OpenPyXL, which seeming has bad word wrap support. However, the formatting can be well preserved.

pyexcel-xlsxwx's People

Contributors

patarapolw avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

wenxuefeng3930

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.