Overview
The CSV Export feature allows you to export data from all three main modules (Inventory, Sales, and Reservations) to CSV (Comma-Separated Values) format. This enables offline analysis, backup, reporting, and integration with external systems.
All exports use standard CSV format:
Field Separator : Comma (,)
Header Row : Column names in the first row
Encoding : UTF-8
Line Endings : \n (newline)
Extension : .csv
CSV files can be opened in Microsoft Excel, Google Sheets, LibreOffice Calc, or any spreadsheet application.
Exporting Inventory Data
How to Export
Open Inventory View
Ensure you’re in the main inventory view (InventarioView).
Click Export Button
Click the Exportar a Excel button in the bottom button panel.
Choose Save Location
Select a directory and filename in the file chooser dialog.
Default filename: inventario.csv
Confirm Export
Click Save . A success message will appear with the file path.
Method Signature
public void exportarInventarioCSV ( File fileToSave)
Controller : InventarioController.java:88-90
DAO Implementation : InventarioDAO.java:459-482
Header Row:
ID, Nombre, Existencias, Lote, Caducidad, Fecha Entrada
Example Data:
ID, Nombre, Existencias, Lote, Caducidad, Fecha Entrada
1, Amoxicilina 500mg, 50, BATCH-2025-001, 2026-12, 2025-03-01
2, Meloxicam 15mg, 30, BATCH-2025-002, 2026-08, 2025-03-02
3, Cefalexina 250mg, 25, BATCH-2025-003, 2027-01, 2025-03-03
Implementation Details
// InventarioDAO.java:459-482
public void exportarInventarioCSV ( File fileToSave) {
try ( FileWriter writer = new FileWriter (fileToSave);
Statement stmt = this . connection . createStatement ();
ResultSet rs = stmt . executeQuery ( "SELECT id, nombre, existencias, lote, caducidad, fechaEntrada FROM productos" )) {
// Write CSV header for inventory
writer . append ( "ID,Nombre,Existencias,Lote,Caducidad,Fecha Entrada \n " );
// Iterate over each row and write data
while ( rs . next ()) {
writer . append ( String . valueOf ( rs . getInt ( "id" ))). append ( "," );
writer . append ( rs . getString ( "nombre" )). append ( "," );
writer . append ( String . valueOf ( rs . getInt ( "existencias" ))). append ( "," );
writer . append ( rs . getString ( "lote" )). append ( "," );
writer . append ( rs . getString ( "caducidad" )). append ( "," );
writer . append ( rs . getString ( "fechaEntrada" )). append ( " \n " );
}
writer . flush ();
JOptionPane . showMessageDialog ( null , "Inventario exportado con éxito en: \n " + fileToSave . getAbsolutePath ());
} catch ( Exception e ) {
e . printStackTrace ();
JOptionPane . showMessageDialog ( null , "Error al exportar el inventario: " + e . getMessage ());
}
}
The fecha_separado field is NOT included in the inventory export. Use the reservations export to see reservation dates.
Exporting Sales Data
How to Export
Open Sales View
Click Ventas in the main inventory view to open the sales history.
Click Export Button
Click the Exportar Reporte button in the sales view.
Choose Save Location
Select a directory and filename.
Default filename: reporte_ventas.csv
Confirm Export
Click Save . The file will be created with all visible sales records.
Alternative Export Method
There’s also a legacy export method accessible via the controller:
public void exportarCSV ( File fileToSave)
Controller : InventarioController.java:83-85
DAO Implementation : InventarioDAO.java:199-215
The legacy exportarCSV method exports a simplified format without product IDs. Use the Exportar Reporte button in VentasView for complete data.
Header Row:
ID Venta, ID Producto, Nombre del Medicamento, Cantidad Vendida, Fecha de Venta
Example Data:
ID Venta, ID Producto, Nombre del Medicamento, Cantidad Vendida, Fecha de Venta
1, 5, Amoxicilina 500mg, 10, 2025-03-01
2, 12, Meloxicam 15mg, 5, 2025-03-02
3, 5, Amoxicilina 500mg, 15, 2025-03-03
Implementation (VentasView)
// VentasView.java:284-307
private void exportarReporte () {
JFileChooser fileChooser = new JFileChooser ();
fileChooser . setDialogTitle ( "Guardar Reporte de Ventas" );
fileChooser . setSelectedFile ( new File ( "reporte_ventas.csv" ));
int selection = fileChooser . showSaveDialog ( this );
if (selection == JFileChooser . APPROVE_OPTION ) {
File file = fileChooser . getSelectedFile ();
try ( java . io . FileWriter writer = new java. io . FileWriter (file)) {
writer . append ( "ID Venta, ID Producto, Nombre del Medicamento, Cantidad Vendida, Fecha de Venta \n " );
for ( int row = 0 ; row < model . getRowCount (); row ++ ) {
for ( int col = 0 ; col < model . getColumnCount (); col ++ ) {
Object value = model . getValueAt (row, col);
writer . append (value != null ? value . toString () : "" );
if (col < model . getColumnCount () - 1 ) writer . append ( "," );
}
writer . append ( " \n " );
}
writer . flush ();
JOptionPane . showMessageDialog ( this , "Reporte exportado con éxito." );
} catch ( Exception e ) {
JOptionPane . showMessageDialog ( this , "Error al exportar el reporte: " + e . getMessage (), "Error" , JOptionPane . ERROR_MESSAGE );
}
}
}
Filtered Exports : The VentasView export includes only the rows currently displayed in the table. Apply filters before exporting to create targeted reports.
Header Row:
Nombre, Cantidad Vendida, Fecha de Venta
Example Data:
Nombre, Cantidad Vendida, Fecha de Venta
Amoxicilina 500mg, 10, 2025-03-01
Meloxicam 15mg, 5, 2025-03-02
Implementation:
// InventarioDAO.java:199-215
public void exportarCSV ( File fileToSave) {
try ( FileWriter writer = new FileWriter (fileToSave);
Statement stmt = this . connection . createStatement ();
ResultSet rs = stmt . executeQuery ( "SELECT nombre, cantidad, fechaVenta FROM historial_ventas" )) {
writer . append ( "Nombre, Cantidad Vendida, Fecha de Venta \n " );
while ( rs . next ()) {
writer . append ( rs . getString ( "nombre" )). append ( "," );
writer . append ( String . valueOf ( rs . getInt ( "cantidad" ))). append ( "," );
writer . append ( rs . getString ( "fechaVenta" ) != null ? rs . getString ( "fechaVenta" ) : "N/A" ). append ( " \n " );
}
writer . flush ();
JOptionPane . showMessageDialog ( null , "CSV exportado con éxito en: \n " + fileToSave . getAbsolutePath ());
} catch ( Exception e ) {
e . printStackTrace ();
JOptionPane . showMessageDialog ( null , "Error al exportar CSV: " + e . getMessage ());
}
}
Exporting Reservation Data
How to Export
Open Reservations View
Click Apartados in the main inventory view.
Click Export Button
Click the Exportar a Excel button in the apartados view.
Choose Save Location
Select a directory and filename.
Default filename: apartados.csv
Confirm Export
Click Save . The file will include all reserved products.
Method Signature
public void exportarApartadosCSV ( File fileToSave)
Controller : InventarioController.java:115-117
DAO Implementation : InventarioDAO.java:591-612
Header Row:
ID, Nombre, Existencias, Lote, Caducidad, Fecha Entrada, Fecha Apartado
Example Data:
ID, Nombre, Existencias, Lote, Caducidad, Fecha Entrada, Fecha Apartado
5, Amoxicilina 500mg, 20, BATCH-001, 2026-12, 2025-03-01, 2025-03-05
12, Meloxicam 15mg, 15, BATCH-002, 2026-08, 2025-02-15, 2025-03-06
Implementation Details
// InventarioDAO.java:591-612
public void exportarApartadosCSV ( File fileToSave) {
try ( FileWriter writer = new FileWriter (fileToSave);
Statement stmt = connection . createStatement ();
ResultSet rs = stmt . executeQuery (
"SELECT id, nombre, existencias, lote, caducidad, fechaEntrada, fecha_separado " +
"FROM productos WHERE fecha_separado IS NOT NULL AND fecha_separado <> ''" )) {
writer . append ( "ID,Nombre,Existencias,Lote,Caducidad,Fecha Entrada,Fecha Apartado \n " );
while ( rs . next ()) {
writer . append ( String . valueOf ( rs . getInt ( "id" ))). append ( "," );
writer . append ( rs . getString ( "nombre" )). append ( "," );
writer . append ( String . valueOf ( rs . getInt ( "existencias" ))). append ( "," );
writer . append ( rs . getString ( "lote" )). append ( "," );
writer . append ( rs . getString ( "caducidad" )). append ( "," );
writer . append ( rs . getString ( "fechaEntrada" )). append ( "," );
writer . append ( rs . getString ( "fecha_separado" )). append ( " \n " );
}
writer . flush ();
JOptionPane . showMessageDialog ( null , "CSV de Apartados exportado con éxito en: \n " + fileToSave . getAbsolutePath ());
} catch ( Exception e ) {
e . printStackTrace ();
JOptionPane . showMessageDialog ( null , "Error al exportar CSV de Apartados: " + e . getMessage ());
}
}
Only products with a non-null fecha_separado are included in this export.
Common Use Cases
Backup and Recovery
Export all three datasets weekly to create backup copies:
Inventory CSV - Complete product database
Sales CSV - Transaction history
Reservations CSV - Pending customer orders
Store backups in multiple locations (local drive, cloud storage, external drive).
Financial Reporting
Open VentasView and filter by date range
Export filtered results to CSV
Open in Excel/Sheets
Use SUM, AVERAGE functions to calculate:
Total units sold
Revenue (if you add pricing)
Top-selling products
Sales trends
Inventory Analysis
Export inventory CSV
Sort by Existencias column
Identify:
Low stock items (reorder needed)
Overstocked items
Stock value by batch
Expiration risk by stock level
Supplier Reports
Export inventory and filter by Lote column to:
Track products from specific suppliers
Prepare quality reports by batch
Manage product recalls
Verify batch rotation (FEFO)
Import into Spreadsheet Applications
Microsoft Excel
Open Excel
Launch Microsoft Excel.
Open CSV File
File → Open → Select your .csv file
Verify Encoding
If special characters appear incorrectly, use Data → Get Data → From Text/CSV and select UTF-8 encoding.
Google Sheets
Open Google Sheets
Go to sheets.google.com
Import File
File → Import → Upload → Select your .csv file
Configure Import
Import location: New spreadsheet
Separator type: Comma
Convert text to numbers: Yes
LibreOffice Calc
Open Calc
Launch LibreOffice Calc.
Open CSV
File → Open → Select .csv file
Text Import Dialog
Character set: UTF-8
Separated by: Comma
Click OK
Error Handling
Common Issues
Error : Cannot write to the selected location.Solutions :
Choose a different directory (e.g., Desktop or Documents)
Close the file if it’s already open in another application
Run the application with appropriate permissions
Error : File already exists.Solutions :
The system will overwrite the existing file
Rename the new export to avoid overwriting
Move the old file to a backup location first
Special Characters Display Incorrectly
Error : Accented characters (á, é, í, ó, ú, ñ) appear as strange symbols.Solution :
When importing, explicitly select UTF-8 encoding
In Excel: Data → Get Data → From Text/CSV → File Origin: UTF-8
Database Connection Errors
// Error handling in DAO
catch ( Exception e ) {
e . printStackTrace ();
JOptionPane . showMessageDialog ( null , "Error al exportar: " + e . getMessage ());
}
If export fails, check:
Database connection is active
Disk space is sufficient
Write permissions are granted
Best Practices
Consistent Naming : Use a naming convention for exports:
inventario_2025-03-15.csv
ventas_2025-03.csv
apartados_2025-Q1.csv
Regular Exports : Schedule weekly exports to maintain backup history and track changes over time.
Version Control : Keep multiple versions of exports to track inventory changes and detect data entry errors.
Filtered Exports : Use table filters before exporting sales data to create targeted reports (e.g., sales by product, sales by date range).
Data Security : CSV files contain sensitive business data. Store them securely and limit access appropriately.
Advanced CSV Processing
Automating with Scripts
CSV files can be processed with Python, R, or other data analysis tools:
import pandas as pd
# Read inventory CSV
df = pd.read_csv( 'inventario.csv' )
# Filter products expiring in 2025-06
expiring_soon = df[df[ 'Caducidad' ] == '2025-06' ]
# Calculate total stock value (if price data available)
total_units = df[ 'Existencias' ].sum()
print ( f "Total units in stock: { total_units } " )
print ( f "Products expiring in June 2025: { len (expiring_soon) } " )
Database Import
Import CSV data into other database systems:
-- PostgreSQL example
COPY productos(id, nombre, existencias, lote, caducidad, fechaEntrada)
FROM '/path/to/inventario.csv'
DELIMITER ','
CSV HEADER;
Import CSV files into BI tools:
Tableau : Connect to CSV file as data source
Power BI : Get Data → Text/CSV
Looker Studio : Upload CSV as data source
Create dashboards by regularly exporting data and loading it into BI tools for visualization and trend analysis.