Chargement d'Excel à partir d'une base de données SQL
using IronXL;
using System.Data;
using System.Data.SqlClient;
// Your sql query
string sql = "SELECT * FROM Users";
// Your connection string
string connectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=usersdb;Integrated Security=True";
using (SqlConnection connection = new SqlConnection(connectionString))
{
// Open connections to the database
connection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);
DataSet ds = new DataSet();
// Fill DataSet with data
adapter.Fill(ds);
// Create an Excel workbook from the SQL DataSet
WorkBook workBook = WorkBook.Load(ds);
}
Imports IronXL
Imports System.Data
Imports System.Data.SqlClient
' Your sql query
Private sql As String = "SELECT * FROM Users"
' Your connection string
Private connectionString As String = "Data Source=.\SQLEXPRESS;Initial Catalog=usersdb;Integrated Security=True"
Using connection As New SqlConnection(connectionString)
' Open connections to the database
connection.Open()
Dim adapter As New SqlDataAdapter(sql, connection)
Dim ds As New DataSet()
' Fill DataSet with data
adapter.Fill(ds)
' Create an Excel workbook from the SQL DataSet
Dim workBook As WorkBook = WorkBook.Load(ds)
End Using
Install-Package IronXL.Excel
Chargement d'Excel à partir d'une base de données SQL
IronXL nous permet de créer un classeur Excel à partir d'un jeu de données SQL en utilisant System.Data.
Comment charger Excel à partir d'une base de données SQL dans C# ;