tablas-python 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.
- tablas_python-0.1.0/LICENSE +21 -0
- tablas_python-0.1.0/PKG-INFO +375 -0
- tablas_python-0.1.0/README.md +339 -0
- tablas_python-0.1.0/helpers/__init__.py +27 -0
- tablas_python-0.1.0/helpers/display_helper.py +135 -0
- tablas_python-0.1.0/helpers/table_manager.py +418 -0
- tablas_python-0.1.0/pyproject.toml +67 -0
- tablas_python-0.1.0/setup.cfg +4 -0
- tablas_python-0.1.0/tablas_python/__init__.py +68 -0
- tablas_python-0.1.0/tablas_python/cli.py +49 -0
- tablas_python-0.1.0/tablas_python.egg-info/PKG-INFO +375 -0
- tablas_python-0.1.0/tablas_python.egg-info/SOURCES.txt +25 -0
- tablas_python-0.1.0/tablas_python.egg-info/dependency_links.txt +1 -0
- tablas_python-0.1.0/tablas_python.egg-info/entry_points.txt +3 -0
- tablas_python-0.1.0/tablas_python.egg-info/requires.txt +12 -0
- tablas_python-0.1.0/tablas_python.egg-info/top_level.txt +3 -0
- tablas_python-0.1.0/utils/__init__.py +71 -0
- tablas_python-0.1.0/utils/batch_processor.py +111 -0
- tablas_python-0.1.0/utils/data_helpers.py +500 -0
- tablas_python-0.1.0/utils/excel_extractor.py +425 -0
- tablas_python-0.1.0/utils/excel_writer.py +188 -0
- tablas_python-0.1.0/utils/exporter.py +158 -0
- tablas_python-0.1.0/utils/file_utils.py +65 -0
- tablas_python-0.1.0/utils/pdf_extractor.py +129 -0
- tablas_python-0.1.0/utils/sqlite_extractor.py +133 -0
- tablas_python-0.1.0/utils/table_cleaner.py +246 -0
- tablas_python-0.1.0/utils/validator.py +155 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Reciba
|
|
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.
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tablas-python
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Suite modular para extraer, transformar, conciliar y exportar tablas desde PDF, Excel y SQLite a pandas.
|
|
5
|
+
Author: Reciba
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Reciba/tablas_python
|
|
8
|
+
Project-URL: Repository, https://github.com/Reciba/tablas_python.git
|
|
9
|
+
Project-URL: Issues, https://github.com/Reciba/tablas_python/issues
|
|
10
|
+
Keywords: tables,pdf,excel,xlwings,pdfplumber,sqlite,pandas,data-extraction,vlookup,conciliation
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Topic :: Office/Business :: Financial :: Spreadsheet
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
21
|
+
Requires-Python: >=3.8
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: pandas>=1.5.0
|
|
25
|
+
Requires-Dist: pdfplumber>=0.9.0
|
|
26
|
+
Requires-Dist: openpyxl>=3.1.0
|
|
27
|
+
Requires-Dist: xlwings>=0.30.0
|
|
28
|
+
Requires-Dist: rich>=13.0.0
|
|
29
|
+
Requires-Dist: numpy>=1.20.0
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: build; extra == "dev"
|
|
32
|
+
Requires-Dist: twine; extra == "dev"
|
|
33
|
+
Requires-Dist: pytest; extra == "dev"
|
|
34
|
+
Requires-Dist: reportlab>=3.6.0; extra == "dev"
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
|
|
37
|
+
# 📊 Tablas Python - Suite Integral de Procesamiento de Tablas
|
|
38
|
+
|
|
39
|
+
Sistema modular en Python diseñado para **reconocer, extraer, transformar, conciliar, validar y exportar tablas** provenientes de múltiples fuentes:
|
|
40
|
+
- 📄 **Documentos PDF** (usando `pdfplumber` con descarte de filas de basura iniciales)
|
|
41
|
+
- 📊 **Archivos Excel / CSV** (usando `xlwings`, compatible con libros **abiertos** o **cerrados**, tablas oficiales `ListObjects`, celdas de inicio y rangos)
|
|
42
|
+
- 🗄️ **Bases de Datos SQLite** (archivos `.db`, `.sqlite`, `.sqlite3`)
|
|
43
|
+
|
|
44
|
+
Además, incluye un conjunto completo de herramientas para **cálculos rápidos (IVA, márgenes, % participación), formateo de monedas/porcentajes, cruces tipo `BUSCARV`, conciliación automática de tablas, escritura en vivo en Excel, unión masiva de carpetas y reportes de calidad de datos**.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## 📁 Arquitectura del Proyecto
|
|
49
|
+
|
|
50
|
+
El código está estructurado de forma modular y desacoplada por capas:
|
|
51
|
+
|
|
52
|
+
```text
|
|
53
|
+
tablas_python/
|
|
54
|
+
│
|
|
55
|
+
├── main.py # Script principal con todas las utilidades importadas y listas para usar
|
|
56
|
+
├── requirements.txt # Dependencias del proyecto
|
|
57
|
+
├── README.md # Documentación técnica completa
|
|
58
|
+
├── .gitignore # Exclusiones de Git
|
|
59
|
+
│
|
|
60
|
+
├── utils/ # Capa de bajo nivel (lógica desacoplada y reutilizable)
|
|
61
|
+
│ ├── __init__.py # Exportaciones unificadas del paquete utils
|
|
62
|
+
│ ├── file_utils.py # Resolución de rutas (relativas/absolutas) y nombres seguros
|
|
63
|
+
│ ├── pdf_extractor.py # Extracción multipágina en PDF con pdfplumber
|
|
64
|
+
│ ├── excel_extractor.py # Extracción en Excel con xlwings (tablas oficiales, celdas y rangos)
|
|
65
|
+
│ ├── excel_writer.py # Escritura en Excel en vivo o en segundo plano con xlwings
|
|
66
|
+
│ ├── sqlite_extractor.py # Extracción y consultas SQL en SQLite
|
|
67
|
+
│ ├── table_cleaner.py # Limpieza, descarte de basura superior, tipos y normalización
|
|
68
|
+
│ ├── batch_processor.py # Unión masiva de carpetas con múltiples archivos a 1 DataFrame
|
|
69
|
+
│ ├── validator.py # Validación de esquemas, diagnóstico de calidad y duplicados
|
|
70
|
+
│ ├── exporter.py # Exportación individual y por lotes a CSV/Excel (utf-8-sig / sep=';')
|
|
71
|
+
│ └── data_helpers.py # Cálculos: BUSCARV, conciliación, IVA, %, totales, celdas y formato
|
|
72
|
+
│
|
|
73
|
+
├── helpers/ # Capa de fachada y presentación
|
|
74
|
+
│ ├── __init__.py # Exportaciones unificadas del paquete helpers
|
|
75
|
+
│ ├── table_manager.py # TableManager unificado, obtener_tabla y exportar_archivo_a_csv
|
|
76
|
+
│ └── display_helper.py # Visualizador enriquecido en consola con Rich
|
|
77
|
+
│
|
|
78
|
+
├── samples/ # Archivos y generador de prueba
|
|
79
|
+
│ ├── generate_samples.py # Script generador de datos de prueba
|
|
80
|
+
│ ├── ejemplo_facturas.pdf # PDF de muestra con tablas y encabezados desplazados
|
|
81
|
+
│ ├── ejemplo_inventario.xlsx # Excel con tablas oficiales, celdas específicas y múltiples hojas
|
|
82
|
+
│ └── ejemplo_empresa.db # Base SQLite de muestra con tablas 'clientes', 'ventas' y vistas
|
|
83
|
+
│
|
|
84
|
+
└── exports/ # Carpeta por defecto para salidas CSV y Excel
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## 🚀 Instalación
|
|
90
|
+
|
|
91
|
+
Clona el repositorio e instala las dependencias:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
git clone https://github.com/Reciba/tablas_python.git
|
|
95
|
+
cd tablas_python
|
|
96
|
+
pip install -r requirements.txt
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## 💡 Guía de Uso Completa
|
|
102
|
+
|
|
103
|
+
### 1. Extracción desde PDF (`pdfplumber`)
|
|
104
|
+
|
|
105
|
+
Resuelve el problema donde las filas 1, 2 o 3 contienen títulos, membretes o metadatos irrelevantes y los encabezados reales comienzan más abajo (por ejemplo en la **fila 4**):
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from helpers.table_manager import obtener_tabla, TableManager
|
|
109
|
+
|
|
110
|
+
# Modo 1: En una sola línea indicando tabla 3 y fila 4 como encabezado:
|
|
111
|
+
df = obtener_tabla("samples/ejemplo_facturas.pdf", tabla=3, fila_encabezado=4)
|
|
112
|
+
print(df.head())
|
|
113
|
+
|
|
114
|
+
# Modo 2: Con inspección previa usando TableManager:
|
|
115
|
+
manager = TableManager("samples/ejemplo_facturas.pdf")
|
|
116
|
+
manager.resumen() # Muestra cuántas tablas hay y en qué páginas
|
|
117
|
+
manager.ver_crudo(tabla=1) # Muestra las primeras filas numeradas (Fila 1, Fila 2, Fila 3...)
|
|
118
|
+
df_limpio = manager.get_df(tabla=1, fila_encabezado=4, skip_footer=1)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
### 2. Extracción desde Excel con `xlwings`
|
|
124
|
+
|
|
125
|
+
Soporta conectarse a archivos **abiertos en pantalla** (sin conflictos de bloqueo) o **cerrados en disco** (en segundo plano):
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
from helpers.table_manager import obtener_tabla
|
|
129
|
+
|
|
130
|
+
# A) Por Nombre Oficial de Tabla de Excel (ListObject / Tabla con Formato):
|
|
131
|
+
df_stock = obtener_tabla("samples/ejemplo_inventario.xlsx", tabla="TablaStock")
|
|
132
|
+
|
|
133
|
+
# B) Por Celda de Inicio donde parte la tabla (ej. celda C4 en la hoja 'Despacho'):
|
|
134
|
+
df_despacho = obtener_tabla(
|
|
135
|
+
"samples/ejemplo_inventario.xlsx",
|
|
136
|
+
celda_inicio="C4",
|
|
137
|
+
hoja="Despacho"
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
# C) Por Rango Exacto:
|
|
141
|
+
df_rango = obtener_tabla(
|
|
142
|
+
"samples/ejemplo_inventario.xlsx",
|
|
143
|
+
rango="C4:F8",
|
|
144
|
+
hoja="Despacho"
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
# D) Control de archivo abierto/cerrado:
|
|
148
|
+
# archivo_abierto=None (autodetecta), True (fuerza conexión al Excel abierto), False (abre oculto)
|
|
149
|
+
df = obtener_tabla("reporte.xlsx", tabla=1, fila_encabezado=4, archivo_abierto=True)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
### 3. Extracción y Consultas en SQLite (`.db`, `.sqlite`)
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
from helpers.table_manager import TableManager, obtener_tabla
|
|
158
|
+
|
|
159
|
+
# A) Obtener tabla completa por nombre:
|
|
160
|
+
df_clientes = obtener_tabla("samples/ejemplo_empresa.db", tabla="clientes")
|
|
161
|
+
|
|
162
|
+
# B) Ejecutar consultas SQL personalizadas directamente a DataFrame:
|
|
163
|
+
db = TableManager("samples/ejemplo_empresa.db")
|
|
164
|
+
db.resumen() # Lista tablas y vistas
|
|
165
|
+
|
|
166
|
+
df_ventas = db.query("""
|
|
167
|
+
SELECT c.nombre AS cliente, c.ciudad, v.monto_neto, v.fecha
|
|
168
|
+
FROM clientes c
|
|
169
|
+
JOIN ventas v ON c.id_cliente = v.id_cliente
|
|
170
|
+
WHERE v.estado = 'Pagado'
|
|
171
|
+
""")
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
### 4. Búsqueda de Celdas por Nombre de Fila y Nombre de Columna
|
|
177
|
+
|
|
178
|
+
Puedes acceder a cualquier celda específica mediante nombres sin depender de posiciones numéricas:
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
from utils.data_helpers import obtener_celda, modificar_celda
|
|
182
|
+
|
|
183
|
+
# A) Usando la función helper obtener_celda:
|
|
184
|
+
precio = obtener_celda(df, fila="PROD-101", columna="Precio Unitario")
|
|
185
|
+
print("Precio PROD-101:", precio)
|
|
186
|
+
|
|
187
|
+
# B) Usando set_index nativo de pandas con .at o .loc:
|
|
188
|
+
df_idx = df.set_index("Codigo")
|
|
189
|
+
precio = df_idx.at["PROD-101", "Precio Unitario"]
|
|
190
|
+
cantidad = df_idx.at["PROD-101", "Cantidad"]
|
|
191
|
+
total = float(precio) * float(cantidad)
|
|
192
|
+
|
|
193
|
+
# C) Modificar una celda por su nombre:
|
|
194
|
+
df_actualizado = modificar_celda(df, fila="PROD-101", columna="Precio Unitario", nuevo_valor=49.90)
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
### 5. Cruces de Datos con `buscar_v` (BUSCARV / VLOOKUP en 1 línea)
|
|
200
|
+
|
|
201
|
+
Cruza dos DataFrames asociando datos a partir de una clave en común:
|
|
202
|
+
|
|
203
|
+
```python
|
|
204
|
+
from utils.data_helpers import buscar_v
|
|
205
|
+
|
|
206
|
+
# Trae el nombre del cliente desde df_clientes a df_ventas usando 'id_cliente':
|
|
207
|
+
df_ventas["Nombre_Cliente"] = buscar_v(
|
|
208
|
+
df_origen=df_ventas,
|
|
209
|
+
df_destino=df_clientes,
|
|
210
|
+
clave="id_cliente",
|
|
211
|
+
columna_a_traer="nombre"
|
|
212
|
+
)
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
### 6. Conciliación y Auditoría entre 2 Tablas (`conciliar_tablas`)
|
|
218
|
+
|
|
219
|
+
Compara dos tablas (por ejemplo: extracto bancario vs. registro contable, o inventario físico vs. teórico):
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
from utils.data_helpers import conciliar_tablas
|
|
223
|
+
|
|
224
|
+
resultado = conciliar_tablas(df_sistema, df_banco, clave="id_transaccion")
|
|
225
|
+
|
|
226
|
+
print("Coincidentes:", resultado["coincidentes"]) # Idénticas en ambas tablas
|
|
227
|
+
print("Diferencias:", resultado["diferencias"]) # Existen en ambas pero con valores distintos
|
|
228
|
+
print("Solo en A:", resultado["solo_en_A"]) # Registros que faltan en B
|
|
229
|
+
print("Solo en B:", resultado["solo_en_B"]) # Registros que faltan en A
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
### 7. Escritura en Vivo en Excel con `escribir_en_excel`
|
|
235
|
+
|
|
236
|
+
Pega un DataFrame en una celda exacta de una plantilla Excel que tengas **abierta en pantalla** o **cerrada en disco**, conservando fórmulas y formatos:
|
|
237
|
+
|
|
238
|
+
```python
|
|
239
|
+
from utils.excel_writer import escribir_en_excel
|
|
240
|
+
|
|
241
|
+
escribir_en_excel(
|
|
242
|
+
df=df_reporte,
|
|
243
|
+
archivo_excel="plantilla_ventas.xlsx",
|
|
244
|
+
hoja="Resumen",
|
|
245
|
+
celda_inicio="B5",
|
|
246
|
+
archivo_abierto=None # Detecta automáticamente si la ventana de Excel está abierta
|
|
247
|
+
)
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
### 8. Consolidación Masiva de Carpetas (`unir_archivos_carpeta`)
|
|
253
|
+
|
|
254
|
+
Lee y une decenas de archivos periódicos (facturas PDF, Excels mensuales, etc.) en un solo DataFrame maestro:
|
|
255
|
+
|
|
256
|
+
```python
|
|
257
|
+
from utils.batch_processor import unir_archivos_carpeta
|
|
258
|
+
|
|
259
|
+
df_consolidado = unir_archivos_carpeta(
|
|
260
|
+
carpeta="facturas_2026/",
|
|
261
|
+
extension="pdf",
|
|
262
|
+
tabla=1,
|
|
263
|
+
fila_encabezado=4
|
|
264
|
+
)
|
|
265
|
+
# Agrega automáticamente la columna 'Archivo_Origen' con el nombre de cada archivo
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
### 9. Calidad y Validación de Datos (`validar_dataframe` y `reporte_calidad`)
|
|
271
|
+
|
|
272
|
+
```python
|
|
273
|
+
from utils.validator import validar_dataframe, reporte_calidad, detectar_duplicados
|
|
274
|
+
|
|
275
|
+
# 1. Diagnóstico completo de nulos, completitud y tipos por columna:
|
|
276
|
+
print(reporte_calidad(df))
|
|
277
|
+
|
|
278
|
+
# 2. Validación de reglas de negocio antes de procesar:
|
|
279
|
+
check = validar_dataframe(
|
|
280
|
+
df,
|
|
281
|
+
columnas_requeridas=["id_venta", "monto_neto", "fecha"],
|
|
282
|
+
no_nulos=["id_venta", "monto_neto"],
|
|
283
|
+
tipos_esperados={"monto_neto": "numeric"}
|
|
284
|
+
)
|
|
285
|
+
|
|
286
|
+
if not check["es_valido"]:
|
|
287
|
+
print("❌ Errores encontrados:", check["errores"])
|
|
288
|
+
|
|
289
|
+
# 3. Detección de registros duplicados:
|
|
290
|
+
duplicados = detectar_duplicados(df, columnas_clave=["id_venta"])
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
### 10. Cálculos Rápidos y Formato para Reportes
|
|
296
|
+
|
|
297
|
+
```python
|
|
298
|
+
from utils.data_helpers import (
|
|
299
|
+
aplicar_impuesto,
|
|
300
|
+
calcular_participacion,
|
|
301
|
+
calcular_variacion,
|
|
302
|
+
agregar_fila_totales,
|
|
303
|
+
formatear_dataframe,
|
|
304
|
+
formato_moneda,
|
|
305
|
+
formato_porcentaje,
|
|
306
|
+
limpiar_numero
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
# A) Calcular IVA (19%) y Total Bruto:
|
|
310
|
+
df = aplicar_impuesto(df, col_neto="monto_neto", tasa=0.19)
|
|
311
|
+
|
|
312
|
+
# B) Calcular % de participación sobre el total:
|
|
313
|
+
df = calcular_participacion(df, columna_valor="Total Bruto")
|
|
314
|
+
|
|
315
|
+
# C) Agregar fila final con totales:
|
|
316
|
+
df = agregar_fila_totales(df, columnas_sumar=["monto_neto", "IVA (19%)", "Total Bruto"])
|
|
317
|
+
|
|
318
|
+
# D) Formatear números a moneda ($) y porcentaje (%):
|
|
319
|
+
df_formateado = formatear_dataframe(df, {
|
|
320
|
+
"monto_neto": "moneda",
|
|
321
|
+
"IVA (19%)": "moneda",
|
|
322
|
+
"Total Bruto": "moneda",
|
|
323
|
+
"% Participación": "porcentaje"
|
|
324
|
+
})
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
---
|
|
328
|
+
|
|
329
|
+
### 11. Exportación Fácil a CSV y Excel
|
|
330
|
+
|
|
331
|
+
```python
|
|
332
|
+
from utils.exporter import guardar_csv, guardar_excel
|
|
333
|
+
from helpers.table_manager import exportar_archivo_a_csv
|
|
334
|
+
|
|
335
|
+
# A) Guardar DataFrame individual a CSV (optimizado con ';' y utf-8-sig para Excel):
|
|
336
|
+
guardar_csv(df, "exports/mi_tabla.csv")
|
|
337
|
+
|
|
338
|
+
# B) Guardar a Excel:
|
|
339
|
+
guardar_excel(df, "exports/mi_tabla.xlsx")
|
|
340
|
+
|
|
341
|
+
# C) Exportar TODAS las tablas encontradas en un archivo a CSVs independientes:
|
|
342
|
+
archivos = exportar_archivo_a_csv("samples/ejemplo_facturas.pdf", carpeta_salida="exports/pdf_tablas", fila_encabezado=4)
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## 🖥️ Ejecución por Consola
|
|
348
|
+
|
|
349
|
+
```bash
|
|
350
|
+
# 1. Ejecutar script principal de demostración:
|
|
351
|
+
python main.py
|
|
352
|
+
|
|
353
|
+
# 2. Modo interactivo en terminal (asistente guiado):
|
|
354
|
+
python main.py -i
|
|
355
|
+
|
|
356
|
+
# 3. Exportar todas las tablas de cualquier archivo por línea de comandos:
|
|
357
|
+
python main.py -f "samples/ejemplo_facturas.pdf" -r 4 --export-all "exports/salida_csv"
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
---
|
|
361
|
+
|
|
362
|
+
## 📦 Tecnologías Utilizadas
|
|
363
|
+
|
|
364
|
+
- **[pandas](https://pandas.pydata.org/)**: Manipulación y estructuras tabulares en DataFrames.
|
|
365
|
+
- **[xlwings](https://docs.xlwings.org/)**: Integración avanzada con Microsoft Excel (archivos abiertos/cerrados, rangos y tablas).
|
|
366
|
+
- **[pdfplumber](https://github.com/jsvine/pdfplumber)**: Extracción precisa de texto y tablas multipágina en PDFs.
|
|
367
|
+
- **[openpyxl](https://openpyxl.readthedocs.io/)**: Soporte nativo y fallback para archivos `.xlsx`.
|
|
368
|
+
- **[reportlab](https://www.reportlab.com/)**: Generación de PDFs de prueba.
|
|
369
|
+
- **[rich](https://github.com/Textualize/rich)**: Visualización y formato de tablas en consola.
|
|
370
|
+
|
|
371
|
+
---
|
|
372
|
+
|
|
373
|
+
## 📄 Licencia
|
|
374
|
+
|
|
375
|
+
Distribuido bajo licencia MIT. Consulta `LICENSE` para más información.
|