The Excel to SQL Processor library provides functionality to map Excel files to SQL scripts that insert rows into a data table. It offers two endpoints for processing Excel files and generating SQL scripts.
- Process Excel files (XLS format) and generate SQL scripts for data insertion.
- Customize output SQL scripts with specified table names and column names.
- Validate Excel files and configurations to ensure data integrity.
Just use as regular dependency via maven in POM.xml
<dependency> <groupId>io.github.krzyzyb</groupId> <artifactId>xls2sql</artifactId> <version>1.1.3</version> </dependency>
Don't forget to inform maven that you are using dependencies from github package registry. Update POM.xml with:
<repositories> <repository> <id>github</id> <url>https://maven.pkg.github.com/krzyzyb/xls2sql</url> </repository> </repositories>
Xls2SqlProcessor.process(Path inputFile, Path outputFile)
In the default processing method, Xls2SqlProcessor.process
, provide the path to the input Excel file (inputFile
)
containing the data to insert and the path to the output SQL script file (outputFile
). The library
automatically generates an SQL script with column names extracted from the XLS header and the table name derived
from the output file name.
Xls2SqlProcessor.process(Path inputFile, Path outputFile, OutputFileConfig config)
In the custom processing method, Xls2SqlProcessor.process
, provide the path to the input Excel file
(inputFile
), the path to the output SQL script file (outputFile
), and a custom
configuration (config
). The configuration (OutputFileConfig
) allows you to customize the
table name and column names for the output SQL script.
Path inputFile = Paths.get("./user/Source.xls");
Path outputFile = Paths.get("./user/Destiny.sql");
Xls2SqlProcessor.process(inputFile, outputFile);
OutputFileConfig config = new OutputFileConfig("CustomTableName", Arrays.asList("Column1", "Column2"));
Xls2SqlProcessor.process(inputFile, outputFile, config);
- Java 8 or higher
This library is licensed under the MIT License.