Excel to SQL file

Convert Excel Workbook to SQL Script Files in C# .NET.

Converting an Excel workbook to a SQL script file using C# .NET is a critical process for developers and data professionals who need to migrate data efficiently between spreadsheets and databases. Furthermore, by transforming Excel data into SQL scripts, you can automate the importation process, reduce the risk of manual errors, and ensure that your data is accurately represented in your SQL databases.

REST API for Excel to SQL Conversion

Aspose.Cells Cloud SDK for .NET supports a wide range of Excel formats, including XLS, XLSX, and CSV, allowing for flexibility in handling various types of spreadsheet data. By utilizing this SDK, you can automate the transformation of spreadsheet data into SQL commands, which can then be executed to populate databases.

The first step is to search Aspose.Cells-Cloud in NuGet packages manager and click the Add Package button. Secondly, obtain your client credentials from cloud dashboard. In case you do not have an existing account, simply create a free account by following the instructions specified in the quick start article.

Convert Excel to SQL File in C# .NET

Let’s explore how the cloud-based architecture of REST API provides scalability and ease of integration, and enables us to seamlessly incorporate it into a .NET application.

CellsApi cellsInstance = new CellsApi(clientID, clientSecret);

Firstly, create an object of CellsApi class where we pass client credentials as arguments.

SaveOptions saveOptions = new SaveOptions()

Secondly, create an instance of SaveOptions and define the output file format as SQL.

PostWorkbookSaveAsRequest postworkbookSaveAsRequest = new PostWorkbookSaveAsRequest()

Thirdly, create an instance of PostWorkbookSaveAsRequest where we specify the name of input Excel workbook, name of resultant SQL File and other optional parameters.

var response = cellsInstance.PostWorkbookSaveAs(postworkbookSaveAsRequest);

Call the API to initiate the Excel to SQL conversion. Once the code is successfully executed, the resultant SQL file is saved in the cloud storage.

excel to sql

Preview of Excel workbook to SQL File conversion.

The input Excel file used in the above example can be downloaded from sourceExcel.xlsx.

XLS to SQL using cURL Commands

By integrating Aspose.Cells Cloud and cURL commands for Excel workbook to SQL file conversion, we make an ideal choice for automation and integration into various workflows. The use of cURL commands makes the solution platform-independent, allowing us to automate the conversion process across different operating systems and environments.

The first step in this approach is to generate a JWT access token using the following command:

curl -v "https://api.aspose.cloud/connect/token" \
 -X POST \
 -d "grant_type=client_credentials&client_id=XXXXXXX-b195-426c-85f7-XXXXXXXX&client_secret=XXXXXXXXXXXXXXXXXXXXXXXXX" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -H "Accept: application/json"

Once we have the JWT access token, please execute the following command to export Excel workbook to SQL file.

curl -v "https://api.aspose.cloud/v3.0/cells/{sourceFile}?format=SQL&isAutoFit=false&onlySaveTable=false&outPath={myResultant}" \
-X GET \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-d {}

Replace sourceFile with the name of input Excel workbook available in the cloud storage, myResultant with the name of resultant SQL file and accessToken with JWT access token generated above.

In order to save the resultant SQL file to local drive, please execute the following cURL command.

curl -v "https://api.aspose.cloud/v3.0/cells/{sourceFile}?format=SQL&isAutoFit=false&onlySaveTable=false" \
-X GET \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-o "myResultant.sql"

Free Excel to SQL Conversion App

In order to quickly witness the capabilities of our REST APIs, please try using our lightweight and supper-efficient Excel to SQL File Conversion App. This free App is built on top of Aspose.Cloud APIs and can be tested online without any installation requirements.

excel to sql

Excel to SQL File conversion App.

Conclusion

In conclusion, converting Excel workbooks to SQL script files using C# .NET is a crucial capability for developers and data professionals seeking efficient data migration and integration solutions. Whether leveraging the powerful Aspose.Cells Cloud SDK for .NET or employing cURL commands, these methods offer robust and flexible approaches to transform spreadsheet data into SQL commands.

We highly recommend visiting the following blogs: