Skip to content

i-net-software/ExcelJConnect

Repository files navigation

Build License Maven JitPack

A Excel driver (*.xlsx) written completely in Java (pure Java).

Dependencies

No dependencies to other libraries are needed.

repositories {
    mavenCentral()
}

dependencies {
    implementation 'de.inetsoftware:exceljconnect:+'
}

Usage

Connection conn = DriverManager.getConnection( "jdbc:inetexcel:{xlsx file}?hasHeaderRow=false" );
DatabaseMetaData metaData = conn.getMetaData();

// lists all available sheets
try( ResultSet rs = metaData.getProcedures( null, null, null ) ) {
	while( rs.next() ) {
		String sheet = rs.getString( "PROCEDURE_NAME" );
		System.out.println( sheet );
	}
}

// lists all available sheets with their columns 
try( ResultSet rs = metaData.getProcedureColumns( null, null, null, null ) ) {
	while( rs.next() ) {
		String sheet = rs.getString( "PROCEDURE_NAME" );
		String column = rs.getString( "COLUMN_NAME" );
		System.out.println( sheet + " / " + column );
	}
}

// lists all available columns from specified sheet
try( ResultSet rs = metaData.getProcedureColumns( null, null, "SheetName", null ) ) {
	while( rs.next() ) {
		String column = rs.getString( "COLUMN_NAME" );
		System.out.println( column );
	}
}

// reads data from specified sheet
try( CallableStatement stm = conn.prepareCall( "{call SheetName}" ); ResultSet rs = stm.executeQuery() ) {
	while( rs.next() ) {
		String columnValue = rs.getString( "ColumnName" );
		String otherColumnValue = rs.getString( "OtherColumnName" );
		System.out.println( columnValue + ", " + otherColumnValue );
	}
}