Voici un exemple de code que j'utilise, et je ne vois pas le problème. Je crée un nouveau classeur/feuille de calcul, puis je remplis une seule ligne et une seule colonne. Pouvez-vous poster votre code et nous pouvons voir quelles sont les différences?
static void Main(string[] args)
{
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Temp\SOTest2.xls;Extended Properties=""Excel 8.0;HDR=NO;""";
DbProviderFactory factory =
DbProviderFactories.GetFactory("System.Data.OleDb");
using (DbConnection connection = factory.CreateConnection())
{
connection.ConnectionString = connectionString;
using (DbCommand command = connection.CreateCommand())
{
connection.Open(); //open the connection
command.CommandText = "CREATE TABLE [Sheet1] (F1 number);";
command.ExecuteNonQuery(); //create the sheet before doing any inserts
command.CommandText = "INSERT INTO [Sheet1$] (F1) VALUES(4)";
command.ExecuteNonQuery(); //now insert a row into the sheet
}
}
}
Je ne vois pas aussi une ligne vide si j'insérer une ligne unique avec plusieurs colonnes:
command.CommandText = "CREATE TABLE [Sheet1] (F1 number, F2 char(255), F3 char(128))";
command.ExecuteNonQuery(); //create the sheet before doing any inserts
command.CommandText = "INSERT INTO [Sheet1$] (F1, F2, F3) VALUES(4,\"Tampa\",\"Florida\")";
command.ExecuteNonQuery(); //now insert a row into the sheet
Hope this helps!