primer commit

This commit is contained in:
Isidoro Nevares Martín 2025-11-10 10:03:07 +01:00
commit 4c6e932c2c
8 changed files with 199 additions and 0 deletions

40
.classpath Normal file
View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target/
*.class

23
.project Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ProyectosIES-Excel</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

Binary file not shown.

21
pom.xml Normal file
View File

@ -0,0 +1,21 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ProyectosIES-Excel</groupId>
<artifactId>ProyectosIES-Excel</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.4.0</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,101 @@
package org.lapaloma.proyectosies;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Date;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
public class AppPrincipal {
private static int INDICE_GASTOS = 0;
private static int INDICE_INGRESOS = 1;
public static void main(String[] args) {
AppPrincipal app = new AppPrincipal();
try {
File f = new File("ficheros/Gastos-Ingresos_Hiperbaric_2024-2025.xlsx");
InputStream inputStream = new FileInputStream(f);
Workbook libroHiperbaric= WorkbookFactory.create(inputStream);
Sheet hojaGastos = libroHiperbaric.getSheetAt(INDICE_GASTOS);
app.tratarGastosExcel(hojaGastos);
Sheet hojaIngresos=libroHiperbaric.getSheetAt(INDICE_INGRESOS);
app.tratarGastosExcel(hojaIngresos);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void tratarIngresosExcel(Sheet hojaIngresos) throws Exception {
int filaInicio = 3; // En la fila 3 comienzan los datos.
Row filaTrabajo = hojaIngresos.getRow(filaInicio); // En qué fila empezar ya dependerá también de si tenemos, por
// ejemplo, el título de cada columna en la primera fila
while (filaTrabajo != null) {
// Concepto - celda 1
Cell celdaConcepto = filaTrabajo.getCell(1);
String concepto = celdaConcepto.getStringCellValue();
// Precio por concepto - celda 1
Cell celdaCantidad = filaTrabajo.getCell(2);
double cantidadUnidad = celdaCantidad.getNumericCellValue();
// Número de unidades - celda 3
Cell celdaNumeroElementos = filaTrabajo.getCell(3);
double numeroUnidades = celdaNumeroElementos.getNumericCellValue();
System.out.println("Concepto: " + concepto);
System.out.println("Número unidades: " + numeroUnidades);
System.out.println("Cantidad por unidad: " + cantidadUnidad);
filaInicio++;
filaTrabajo = hojaIngresos.getRow(filaInicio);
System.out.println();
}
}
private void tratarGastosExcel(Sheet hojaGastos) throws Exception {
int filaInicio = 3; // En la fila 3 comienzan los datos.
Row filaTrabajo = hojaGastos.getRow(filaInicio); // En qué fila empezar ya dependerá también de si tenemos, por
// ejemplo, el título de cada columna en la primera fila
while (filaTrabajo != null) {
// Patrocinador - celda 1
Cell celdaPatrocinador = filaTrabajo.getCell(1);
String patrocinador = celdaPatrocinador.getStringCellValue();
// Importe - celda 2
Cell celdaCantidad = filaTrabajo.getCell(2);
double cantidad = celdaCantidad.getNumericCellValue();
// Observación - celda 3
Cell celdaObservacion = filaTrabajo.getCell(3);
// String observacion = celdaObservacion.getStringCellValue();
// Fecha - celda 4
Cell celdaFecha= filaTrabajo.getCell(4);
String fecha = celdaFecha.getStringCellValue();
System.out.println("Patrocinador: " + patrocinador);
System.out.println("Cantidad: " + cantidad);
System.out.println("Observación: " + celdaObservacion);
System.out.println("Fecha: " + fecha);
filaInicio++;
filaTrabajo = hojaGastos.getRow(filaInicio);
System.out.println();
}
}
}