Convert excel table to latex table

A powerful tool that converts excel table to latex table in human-readable format.

Before conversion

  • Don’t use theme colors that excel show in the panel, otherwise your color will not be recognized. standard colors or more colors will be ok.
  • Font style is specified for the whole text, not a single character, i.e., if you have two characters one of which is bold and another is italic, then they will be both bold and italic.
  • The height of every merged cell must not be less than the number of lines in your text.

Requirements

If you are not using a -e option, please add the following required packages to your preamble:

\usepackage{multirow, makecell}

Following python package is required:

pip install openpyxl

Usage

usage: excel2tex.py [-h] [-s SOURCE] [-o TARGET] [--setting SETTING] [--sig] [-m] [-e]

optional arguments:
  -h, --help            show this help message and exit
  -s SOURCE             source file (default: table.xlsx)
  -o TARGET             target file (default: table.tex)
  --setting SETTING     setting file (default: setting.tex)
  --sig                 set file encoding to utf-8-sig, only use when there is mess code.
  -m, --math            enabel inline math
  -e, --excel-format    enabel all formats

If you are using windows and have no python installed, an executable file is provided here

Simple usage

We have the following excel table to be converted to latex table.

Excel table

python excel2tex.py is the simplest method to do this, which means converting an excel file of name table.xlsx to a tex file of name table.tex. And because you are not using the -e option, the table is resolved in the simplest way:

  • All lines are drawn
  • No element will be colored
  • Text are all centered
  • All characters are converted to what they have been.

So this is the converted table drawn in latex. Generated code is in simple.tex

latex table of simple format

Enable all formats

If you want more styles to be resolved, try to use the -e option. The following command will convert the table with most of the styles you have set in excel. And a setting file of name setting.tex by default (change it by --setting mysetting.tex). Please input the setting file in your preamble. The -m option ensure that the character $ is not escaped so that you can enter the math mode in excel just as in latex.

python excel2tex.py -e -m

Here is the result. The generated code is in all.tex

latex table of all format

Trouble shooting

Mess code

Try to set encoding to utf-8-sig, for example

python excel2tex.py -s table.xlsx -o table.tex --sig

Support

If you have some emergency trouble with this tool, send me your code to my email: [email protected]

Buy me a coffee

Does this tool help you? You can buy me coffee!

wechat alipay

GitHub

View Github