xlfmt 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- xlfmt-0.1.0/LICENSE +21 -0
- xlfmt-0.1.0/PKG-INFO +58 -0
- xlfmt-0.1.0/README.md +44 -0
- xlfmt-0.1.0/pyproject.toml +30 -0
- xlfmt-0.1.0/setup.cfg +4 -0
- xlfmt-0.1.0/src/xlfmt/__init__.py +6 -0
- xlfmt-0.1.0/src/xlfmt/format.py +1403 -0
- xlfmt-0.1.0/src/xlfmt.egg-info/PKG-INFO +58 -0
- xlfmt-0.1.0/src/xlfmt.egg-info/SOURCES.txt +11 -0
- xlfmt-0.1.0/src/xlfmt.egg-info/dependency_links.txt +1 -0
- xlfmt-0.1.0/src/xlfmt.egg-info/top_level.txt +1 -0
- xlfmt-0.1.0/tests/test_format.py +229 -0
- xlfmt-0.1.0/tests/test_openpyxl.py +67 -0
xlfmt-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Wesley
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
xlfmt-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: xlfmt
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Turn an Excel number format and a value into the string Excel shows.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://pypi.org/project/xlfmt/
|
|
7
|
+
Keywords: excel,xlsx,number-format,openpyxl
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# xlfmt
|
|
16
|
+
|
|
17
|
+
`m` in an Excel format means minutes when it sits next to hours or seconds, and months otherwise. Excel also thinks 1900 was a leap year. `xlfmt` turns a format code and a value into the string Excel shows, including fractions and `[Red]`.
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from openpyxl import load_workbook
|
|
21
|
+
from openpyxl.utils.datetime import CALENDAR_MAC_1904
|
|
22
|
+
from xlfmt import format_value
|
|
23
|
+
|
|
24
|
+
wb = load_workbook("report.xlsx")
|
|
25
|
+
ws = wb.active
|
|
26
|
+
cell = ws["B2"]
|
|
27
|
+
|
|
28
|
+
# cell.value -> 0.4375
|
|
29
|
+
# cell.number_format -> "h:mm AM/PM"
|
|
30
|
+
|
|
31
|
+
text = format_value(cell.value, cell.number_format, date1904=wb.epoch == CALENDAR_MAC_1904)
|
|
32
|
+
# text -> "10:30 AM"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`text` is a `str`. When the matching section names a color, `text.color` is that color (`"Red"`, `"Color 3"`, …). Excel paints the color; it is not part of the text.
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
text = format_value(-1234, '#,##0 ;[Red](#,##0)')
|
|
39
|
+
# text == "(1,234)"
|
|
40
|
+
# text.color == "Red"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Pass `date1904=True` for workbooks that use the 1904 date system. In the 1900 system, serial 60 is February 29, 1900.
|
|
44
|
+
|
|
45
|
+
## Install
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install xlfmt
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Develop
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
uv sync
|
|
55
|
+
uv run pytest
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`uv sync` installs the package plus the dev group (`pytest` and `openpyxl`). openpyxl is not a runtime dependency.
|
xlfmt-0.1.0/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# xlfmt
|
|
2
|
+
|
|
3
|
+
`m` in an Excel format means minutes when it sits next to hours or seconds, and months otherwise. Excel also thinks 1900 was a leap year. `xlfmt` turns a format code and a value into the string Excel shows, including fractions and `[Red]`.
|
|
4
|
+
|
|
5
|
+
```python
|
|
6
|
+
from openpyxl import load_workbook
|
|
7
|
+
from openpyxl.utils.datetime import CALENDAR_MAC_1904
|
|
8
|
+
from xlfmt import format_value
|
|
9
|
+
|
|
10
|
+
wb = load_workbook("report.xlsx")
|
|
11
|
+
ws = wb.active
|
|
12
|
+
cell = ws["B2"]
|
|
13
|
+
|
|
14
|
+
# cell.value -> 0.4375
|
|
15
|
+
# cell.number_format -> "h:mm AM/PM"
|
|
16
|
+
|
|
17
|
+
text = format_value(cell.value, cell.number_format, date1904=wb.epoch == CALENDAR_MAC_1904)
|
|
18
|
+
# text -> "10:30 AM"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`text` is a `str`. When the matching section names a color, `text.color` is that color (`"Red"`, `"Color 3"`, …). Excel paints the color; it is not part of the text.
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
text = format_value(-1234, '#,##0 ;[Red](#,##0)')
|
|
25
|
+
# text == "(1,234)"
|
|
26
|
+
# text.color == "Red"
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Pass `date1904=True` for workbooks that use the 1904 date system. In the 1900 system, serial 60 is February 29, 1900.
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install xlfmt
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Develop
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
uv sync
|
|
41
|
+
uv run pytest
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`uv sync` installs the package plus the dev group (`pytest` and `openpyxl`). openpyxl is not a runtime dependency.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "xlfmt"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Turn an Excel number format and a value into the string Excel shows."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
keywords = ["excel", "xlsx", "number-format", "openpyxl"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
]
|
|
18
|
+
dependencies = []
|
|
19
|
+
|
|
20
|
+
[dependency-groups]
|
|
21
|
+
dev = ["pytest>=7", "openpyxl>=3.0"]
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
Homepage = "https://pypi.org/project/xlfmt/"
|
|
25
|
+
|
|
26
|
+
[tool.setuptools.packages.find]
|
|
27
|
+
where = ["src"]
|
|
28
|
+
|
|
29
|
+
[tool.pytest.ini_options]
|
|
30
|
+
testpaths = ["tests"]
|
xlfmt-0.1.0/setup.cfg
ADDED