Я просто хочу обновить существующий файл Excel, используя C#. NET (.XLS) Формат
Этот код работает нормально Спасибо
String sConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + newFile + ";Extended Properties='Excel 8.0;HDR=NO'";
OleDbConnection objConn = new OleDbConnection(sConnectionString);
objConn.Open();
OleDbCommand selectCmd = new OleDbCommand("SELECT * FROM [Sheet1$]", objConn);
OleDbDataAdapter xlAdapter = new OleDbDataAdapter();
xlAdapter.SelectCommand = selectCmd;
DataSet xlDataset = new DataSet();
xlAdapter.Fill(xlDataset, "XLData");
xlAdapter.Dispose();
selectCmd.Dispose();
var thisDates = fDate.ToString("dd/MM/yyyy").Trim() + " TO " +
tDate.ToString("dd/MM/yyyy").Trim();
OleDbCommand cmdUpDates = new OleDbCommand("UPDATE [Sheet1$C5:C5] SET F1='" + thisDates + "'", objConn);
cmdUpDates.ExecuteNonQuery();
cmdUpDates.Dispose();
var totalRows = xlDataset.Tables[0].Rows.Count;
for (int z = 0; z < totalRows; z++)
{
DataRow item = xlDataset.Tables[0].Rows[z];
Int32 oQtyBon = 0;
var idx = z + 1;
OleDbCommand cmdUpOpening = new OleDbCommand
("UPDATE [Sheet1$E" + idx + ":E" + idx + "] SET F1=" + oQtyBon, objConn);
cmdUpOpening.ExecuteNonQuery();
cmdUpOpening.Dispose();
}
objConn.Close();
objConn.Dispose();