enhance the behaivor of pyexcel-xls, return #N/A for cell error. https://github.com/pyexcel/pyexcel/issues/151

This commit is contained in:
chfw 2018-08-21 18:26:50 +01:00
parent 66aece6568
commit b0dd608190
14 changed files with 656 additions and 79 deletions

395
.gitignore vendored
View File

@ -1,5 +1,8 @@
# April 2016
# reference: https://github.com/github/gitignore/blob/master/Python.gitignore
# moban hashes
.moban.hashes
# Extra rules from https://github.com/github/gitignore/
# Python rules
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
@ -10,7 +13,6 @@ __pycache__/
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
@ -22,9 +24,11 @@ lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
@ -44,8 +48,9 @@ htmlcov/
.cache
nosetests.xml
coverage.xml
*,cover
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
@ -54,6 +59,7 @@ coverage.xml
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
@ -68,7 +74,7 @@ docs/_build/
# PyBuilder
target/
# IPython Notebook
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
@ -77,23 +83,388 @@ target/
# celery beat schedule file
celerybeat-schedule
# dotenv
.env
# SageMath parsed files
*.sage.py
# virtualenv
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# emacs
# mkdocs documentation
/site
# mypy
.mypy_cache/
# VirtualEnv rules
# Virtualenv
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
.Python
[Bb]in
[Ii]nclude
[Ll]ib
[Ll]ib64
[Ll]ocal
[Ss]cripts
pyvenv.cfg
.venv
pip-selfcheck.json
# Linux rules
*~
# moban hashes
.moban.hashes
.DS_store
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
# Windows rules
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
# macOS rules
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# Emacs rules
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*
# Org-mode
.org-id-locations
*_archive
# flymake-mode
*_flymake.*
# eshell files
/eshell/history
/eshell/lastdir
# elpa packages
/elpa/
# reftex files
*.rel
# AUCTeX auto folder
/auto/
# cask packages
.cask/
dist/
# Flycheck
flycheck_*.el
# server auth directory
/server/
# projectiles files
.projectile
# directory configuration
.dir-locals.el
# Vim rules
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]
# Session
Session.vim
# Temporary
.netrwhist
*~
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~
# JetBrains rules
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# SublimeText rules
# Cache files for Sublime Text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache
# Workspace files are user-specific
*.sublime-workspace
# Project files should be checked into the repository, unless a significant
# proportion of contributors will probably not be using Sublime Text
# *.sublime-project
# SFTP configuration file
sftp-config.json
# Package control specific files
Package Control.last-run
Package Control.ca-list
Package Control.ca-bundle
Package Control.system-ca-bundle
Package Control.cache/
Package Control.ca-certs/
Package Control.merged-ca-bundle
Package Control.user-ca-bundle
oscrypto-ca-bundle.crt
bh_unicode_properties.cache
# Sublime-github package stores a github token in this file
# https://packagecontrol.io/packages/sublime-github
GitHub.sublime-settings
# KDevelop4 rules
*.kdev4
.kdev4/
# Kate rules
# Swap Files #
.*.kate-swp
.swp.*
# TextMate rules
*.tmproj
*.tmproject
tmtags
# VisualStudioCode rules
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
# Xcode rules
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## User settings
xcuserdata/
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
# Eclipse rules
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# PyDev specific (Python IDE for Eclipse)
*.pydevproject
# CDT-specific (C/C++ Development Tooling)
.cproject
# CDT- autotools
.autotools
# Java annotation processor (APT)
.factorypath
# PDT-specific (PHP Development Tools)
.buildpath
# sbteclipse plugin
.target
# Tern plugin
.tern-project
# TeXlipse plugin
.texlipse
# STS (Spring Tool Suite)
.springBeans
# Code Recommenders
.recommenders/
# Annotation Processing
.apt_generated/
# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet
# TortoiseGit rules
# Project-level settings
/.tgitconfig
# Tags rules
# Ignore tags created by etags, ctags, gtags (GNU global) and cscope
TAGS
.TAGS
!TAGS/
tags
.tags
!tags/
gtags.files
GTAGS
GRTAGS
GPATH
GSYMS
cscope.files
cscope.out
cscope.in.out
cscope.po.out

View File

@ -4,7 +4,7 @@ configuration:
- "commons/templates"
- "setupmobans/templates"
- ".moban.d"
configuration: pyexcel_xls.yaml
configuration: pyexcel-xls.yml
targets:
- README.rst: README.rst
- setup.py: setup.py

View File

@ -4,12 +4,11 @@ notifications:
email: false
python:
- pypy-5.3.1
- 3.7-dev
- 3.6
- 3.5
- 3.4
- 3.3
- 2.7
- 2.6
matrix:
include:
- python: 2.7

View File

@ -5,7 +5,10 @@ pyexcel-xls - Let you focus on data, instead of xls format
.. image:: https://raw.githubusercontent.com/pyexcel/pyexcel.github.io/master/images/patreon.png
:target: https://www.patreon.com/pyexcel
.. image:: https://api.travis-ci.org/pyexcel/pyexcel-xls.svg?branch=master
.. image:: https://api.bountysource.com/badge/team?team_id=288537
:target: https://salt.bountysource.com/teams/chfw-pyexcel
.. image:: https://travis-ci.org/pyexcel/pyexcel-xls.svg?branch=master
:target: http://travis-ci.org/pyexcel/pyexcel-xls
.. image:: https://codecov.io/gh/pyexcel/pyexcel-xls/branch/master/graph/badge.svg
@ -25,7 +28,8 @@ Fonts, colors and charts are not supported.
Installation
================================================================================
You can install it via pip:
You can install pyexcel-xls via pip:
.. code-block:: bash
@ -44,13 +48,16 @@ Support the project
================================================================================
If your company has embedded pyexcel and its components into a revenue generating
product, please `support me on patreon <https://www.patreon.com/bePatron?u=5537627>`_ to
maintain the project and develop it further.
product, please support me on `patreon <https://www.patreon.com/bePatron?u=5537627>`_
or `bounty source <https://salt.bountysource.com/teams/chfw-pyexcel>`_ to maintain
the project and develop it further.
If you are an individual, you are welcome to support me too on patreon and for however long
you feel like to. As a patreon, you will receive
If you are an individual, you are welcome to support me too and for however long
you feel like. As my backer, you will receive
`early access to pyexcel related contents <https://www.patreon.com/pyexcel/posts>`_.
And your issues will get prioritized if you would like to become my patreon as `pyexcel pro user`.
With your financial support, I will be able to invest
a little bit more time in coding, documentation and writing interesting posts.

View File

@ -4,6 +4,45 @@ DESCRIPTION = (
' reads xlsx and xlsm format' +
''
)
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# -- Project information -----------------------------------------------------
project = u'pyexcel-xls'
copyright = u'2015-2018 Onni Software Ltd.'
author = u'C.W.'
# The short X.Y version
version = u'0.5.6'
# The full version, including alpha/beta/rc tags
release = u'0.5.7'
# -- General configuration ---------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
@ -11,34 +50,146 @@ extensions = [
'sphinx.ext.viewcode',
]
intersphinx_mapping = {
'pyexcel': ('http://pyexcel.readthedocs.io/en/latest/', None),
}
spelling_word_list_filename = 'spelling_wordlist.txt'
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
# The master toctree document.
master_doc = 'index'
project = u'pyexcel-xls'
copyright = u'2015-2017 Onni Software Ltd.'
version = '0.5.1'
release = '0.6.0'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'en'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
html_theme = 'default'
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# The default sidebars (for documents that don't match any pattern) are
# defined by theme itself. Builtin themes are using these templates by
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.
#
# html_sidebars = {}
# -- Options for HTMLHelp output ---------------------------------------------
# Output file base name for HTML help builder.
htmlhelp_basename = 'pyexcel-xlsdoc'
latex_elements = {}
# -- Options for LaTeX output ------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
('index', 'pyexcel-xls.tex',
'pyexcel-xls Documentation',
'Onni Software Ltd.', 'manual'),
(master_doc, 'pyexcel-xls.tex', u'pyexcel-xls Documentation',
u'Onni Software Ltd.', 'manual'),
]
# -- Options for manual page output ------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'pyexcel-xls',
'pyexcel-xls Documentation',
[u'Onni Software Ltd.'], 1)
(master_doc, 'pyexcel-xls', u'pyexcel-xls Documentation',
[author], 1)
]
# -- Options for Texinfo output ----------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'pyexcel-xls', u'pyexcel-xls Documentation',
author, 'pyexcel-xls', 'One line description of project.',
'Miscellaneous'),
]
# -- Options for Epub output -------------------------------------------------
# Bibliographic Dublin Core info.
epub_title = project
# The unique identifier of the text. This can be a ISBN number
# or the project homepage.
#
# epub_identifier = ''
# A unique identification for the text.
#
# epub_uid = ''
# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']
# -- Extension configuration -------------------------------------------------
# -- Options for intersphinx extension ---------------------------------------
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}
# TODO: html_theme not configurable upstream
html_theme = 'default'
# TODO: DESCRIPTION not configurable upstream
texinfo_documents = [
('index', 'pyexcel-xls',
'pyexcel-xls Documentation',
@ -46,3 +197,6 @@ texinfo_documents = [
DESCRIPTION,
'Miscellaneous'),
]
intersphinx_mapping.update({
'pyexcel': ('http://pyexcel.readthedocs.io/en/latest/', None),
})

View File

@ -1,9 +1,9 @@
overrides: "pyexcel.yaml"
name: "pyexcel-xls"
nick_name: xls
version: 0.6.0
current_version: 0.6.0
release: 0.5.1
version: 0.5.7
current_version: 0.5.7
release: 0.5.6
file_type: xls
dependencies:
- pyexcel-io>=0.5.0

View File

@ -21,6 +21,7 @@ XLS_KEYWORDS = [
'file_contents', 'encoding_override', 'formatting_info',
'on_demand', 'ragged_rows'
]
DEFAULT_ERROR_VALUE = '#N/A'
class XLSheet(SheetReader):
@ -70,6 +71,8 @@ class XLSheet(SheetReader):
elif cell_type == xlrd.XL_CELL_NUMBER and self.__auto_detect_int:
if has_no_digits_in_float(value):
value = int(value)
elif cell_type == xlrd.XL_CELL_ERROR:
value = DEFAULT_ERROR_VALUE
return value
def _offset_hidden_indices(self, row, column):

View File

@ -1,4 +1,6 @@
# Template by setupmobans
#!/usr/bin/env python3
# Template by pypi-mobans
import os
import sys
import codecs
@ -9,27 +11,24 @@ PY26 = PY2 and sys.version_info[1] < 7
NAME = 'pyexcel-xls'
AUTHOR = 'C.W.'
VERSION = '0.6.0'
VERSION = '0.5.7'
EMAIL = 'wangc_2011@hotmail.com'
LICENSE = 'New BSD'
DESCRIPTION = (
'A wrapper library to read, manipulate and write data in xls format. It' +
' reads xlsx and xlsm format' +
''
'reads xlsx and xlsm format'
)
URL = 'https://github.com/pyexcel/pyexcel-xls'
DOWNLOAD_URL = '%s/archive/0.5.1.tar.gz' % URL
FILES = ['README.rst', 'CHANGELOG.rst']
DOWNLOAD_URL = '%s/archive/0.5.6.tar.gz' % URL
FILES = ['README.rst', 'CHANGELOG.rst']
KEYWORDS = [
'xls',
'xlsx',
'xlsm'
'python'
'xlsm',
'python',
]
CLASSIFIERS = [
'Topic :: Office/Business',
'Topic :: Utilities',
'Topic :: Software Development :: Libraries',
'Programming Language :: Python',
'Intended Audience :: Developers',
@ -47,16 +46,22 @@ INSTALL_REQUIRES = [
'xlrd',
'xlwt',
]
SETUP_COMMANDS = {}
PACKAGES = find_packages(exclude=['ez_setup', 'examples', 'tests'])
EXTRAS_REQUIRE = {
}
# You do not need to read beyond this line
PUBLISH_COMMAND = '{0} setup.py sdist bdist_wheel upload -r pypi'.format(
sys.executable)
GS_COMMAND = ('gs pyexcel-xls v0.5.1 ' +
"Find 0.5.1 in changelog for more details")
here = os.path.abspath(os.path.dirname(__file__))
GS_COMMAND = ('gs pyexcel-xls v0.5.6 ' +
"Find 0.5.6 in changelog for more details")
NO_GS_MESSAGE = ('Automatic github release is disabled. ' +
'Please install gease to enable it.')
UPLOAD_FAILED_MSG = (
'Upload failed. please run "%s" yourself.' % PUBLISH_COMMAND)
HERE = os.path.abspath(os.path.dirname(__file__))
class PublishCommand(Command):
@ -79,17 +84,43 @@ class PublishCommand(Command):
def run(self):
try:
self.status('Removing previous builds...')
rmtree(os.path.join(here, 'dist'))
rmtree(os.path.join(HERE, 'dist'))
rmtree(os.path.join(HERE, 'build'))
rmtree(os.path.join(HERE, 'pyexcel_xls.egg-info'))
except OSError:
pass
self.status('Building Source and Wheel (universal) distribution...')
if os.system(GS_COMMAND) == 0:
os.system(PUBLISH_COMMAND)
run_status = True
if has_gease():
run_status = os.system(GS_COMMAND) == 0
else:
self.status(NO_GS_MESSAGE)
if run_status:
if os.system(PUBLISH_COMMAND) != 0:
self.status(UPLOAD_FAILED_MSG % PUBLISH_COMMAND)
sys.exit()
SETUP_COMMANDS.update({
'publish': PublishCommand
})
def has_gease():
"""
test if github release command is installed
visit http://github.com/moremoban/gease for more info
"""
try:
import gease # noqa
return True
except ImportError:
return False
def read_files(*files):
"""Read files into setup"""
text = ""
@ -101,7 +132,8 @@ def read_files(*files):
def read(afile):
"""Read a file into setup"""
with codecs.open(afile, 'r', 'utf-8') as opened_file:
the_relative_file = os.path.join(HERE, afile)
with codecs.open(the_relative_file, 'r', 'utf-8') as opened_file:
content = filter_out_test_code(opened_file)
content = "".join(list(content))
return content
@ -150,8 +182,5 @@ if __name__ == '__main__':
include_package_data=True,
zip_safe=False,
classifiers=CLASSIFIERS,
setup_requires=['gease'],
cmdclass={
'publish': PublishCommand,
}
cmdclass=SETUP_COMMANDS
)

View File

@ -1,2 +1,2 @@
pip freeze
nosetests --with-coverage --cover-package pyexcel_xls --cover-package tests --with-doctest --doctest-extension=.rst README.rst tests docs/source pyexcel_xls && flake8 . --exclude=.moban.d --builtins=unicode,xrange,long
nosetests --with-coverage --cover-package pyexcel_xls --cover-package tests tests --with-doctest --doctest-extension=.rst README.rst docs/source pyexcel_xls && flake8 . --exclude=.moban.d,docs --builtins=unicode,xrange,long

View File

@ -1,2 +1,2 @@
pip freeze
nosetests --with-coverage --cover-package pyexcel_xls --cover-package tests --with-doctest --doctest-extension=.rst README.rst tests docs/source pyexcel_xls && flake8 . --exclude=.moban.d --builtins=unicode,xrange,long
nosetests --with-coverage --cover-package pyexcel_xls --cover-package tests tests --with-doctest --doctest-extension=.rst README.rst docs/source pyexcel_xls && flake8 . --exclude=.moban.d,docs --builtins=unicode,xrange,long

BIN
tests/fixtures/pyexcel_issue_151.xlsx vendored Normal file

Binary file not shown.

View File

@ -90,5 +90,13 @@ def test_issue_20():
pe.get_book(url="https://github.com/pyexcel/pyexcel-xls/raw/master/tests/fixtures/file_with_an_empty_sheet.xls"); # flake8: noqa
def test_issue_151():
s = pe.get_sheet(
file_name=get_fixture('pyexcel_issue_151.xlsx'),
skip_hidden_row_and_column=False,
library='pyexcel-xls')
eq_('#N/A', s[0,0])
def get_fixture(file_name):
return os.path.join("tests", "fixtures", file_name)

View File

@ -1,6 +1,6 @@
import os
from unittest import TestCase
from textwrap import dedent
from nose.tools import eq_
import pyexcel as pe
@ -10,7 +10,7 @@ class TestDateFormat:
"""
date time
25/12/14 11:11:11
25/12/14 12:11:11
25/12/14 12:12:12
01/01/15 13:13:13
0.0 0.0
"""
@ -18,8 +18,8 @@ class TestDateFormat:
r = pe.get_sheet(file_name=os.path.join("tests", "fixtures",
"date_field.xls"),
library='pyexcel-xls')
assert isinstance(r[1, 0], datetime.date) is True
assert r[1, 0].strftime("%d/%m/%y") == "25/12/14"
assert isinstance(r[1, 0], datetime.date)
eq_(r[1, 0].strftime("%d/%m/%y"), "25/12/14")
assert isinstance(r[1, 1], datetime.time) is True
assert r[1, 1].strftime("%H:%M:%S") == "11:11:11"
assert r[4, 0].strftime("%d/%m/%Y") == "01/01/1900"
@ -42,47 +42,51 @@ class TestDateFormat:
os.unlink(excel_filename)
class TestAutoDetectInt(TestCase):
class TestAutoDetectInt:
def setUp(self):
self.content = [[1, 2, 3.1]]
self.test_file = "test_auto_detect_init.xls"
pe.save_as(array=self.content, dest_file_name=self.test_file)
pe.save_as(
array=self.content, dest_file_name=self.test_file
)
def test_auto_detect_int(self):
sheet = pe.get_sheet(file_name=self.test_file)
sheet = pe.get_sheet(file_name=self.test_file, library="pyexcel-xls")
expected = dedent("""
pyexcel_sheet1:
+---+---+-----+
| 1 | 2 | 3.1 |
+---+---+-----+""").strip()
self.assertEqual(str(sheet), expected)
eq_(str(sheet), expected)
def test_get_book_auto_detect_int(self):
book = pe.get_book(file_name=self.test_file)
book = pe.get_book(file_name=self.test_file, library="pyexcel-xls")
expected = dedent("""
pyexcel_sheet1:
+---+---+-----+
| 1 | 2 | 3.1 |
+---+---+-----+""").strip()
self.assertEqual(str(book), expected)
eq_(str(book), expected)
def test_auto_detect_int_false(self):
sheet = pe.get_sheet(file_name=self.test_file, auto_detect_int=False)
sheet = pe.get_sheet(file_name=self.test_file, auto_detect_int=False,
library="pyexcel-xls")
expected = dedent("""
pyexcel_sheet1:
+-----+-----+-----+
| 1.0 | 2.0 | 3.1 |
+-----+-----+-----+""").strip()
self.assertEqual(str(sheet), expected)
eq_(str(sheet), expected)
def test_get_book_auto_detect_int_false(self):
book = pe.get_book(file_name=self.test_file, auto_detect_int=False)
book = pe.get_book(file_name=self.test_file, auto_detect_int=False,
library="pyexcel-xls")
expected = dedent("""
pyexcel_sheet1:
+-----+-----+-----+
| 1.0 | 2.0 | 3.1 |
+-----+-----+-----+""").strip()
self.assertEqual(str(book), expected)
eq_(str(book), expected)
def tearDown(self):
os.unlink(self.test_file)

View File

@ -11,7 +11,8 @@ class TestStringIO:
create_sample_file1(testfile)
with open(testfile, "rb") as f:
content = f.read()
r = pyexcel.get_sheet(file_type="xls", file_content=content)
r = pyexcel.get_sheet(file_type="xls", file_content=content,
library="pyexcel-xls")
result = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 1.1, 1]
actual = list(r.enumerate())
eq_(result, actual)
@ -25,7 +26,8 @@ class TestStringIO:
]
io = pyexcel.save_as(dest_file_type="xls",
array=data)
r = pyexcel.get_sheet(file_type="xls", file_content=io.getvalue())
r = pyexcel.get_sheet(file_type="xls", file_content=io.getvalue(),
library="pyexcel-xls")
result = [1, 2, 3, 4, 5, 6]
actual = list(r.enumerate())
eq_(result, actual)