1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| private void xlsDriving()
{
object Missing = System.Reflection.Missing.Value;
string fileName = @"c:\\test.xls";
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
Excel._Application xlApp;
Excel._Workbook xlClasseur;
Excel._Worksheet xlFeuill1;
xlApp = new Excel.Application();
xlApp.Visible = false;
xlClasseur = xlApp.Workbooks.Open(fileName, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, true, 0, true, true);
Excel.Sheets xlFeuilles = xlClasseur.Sheets;
xlFeuill1 = (Excel._Worksheet)xlFeuilles["Sheet1"];
if (textBox3.Text != "no data")
{
string Value = textBox3.Text;
Excel.Range r = xlFeuill1.get_Range("B9", Missing);
object[,] cell = (object[,])r.Cells.get_Value(Microsoft.Office.Interop.Excel.XlRangeValueDataType.xlRangeValueDefault);
cell[1, 1] = Value;
}
xlClasseur.Save(); // Enregistre les modifs des cellules
xlClasseur.Close(false, Missing, Missing); // ferme le XLS
xlApp.Quit(); // On met fin au pilotage
} |
Partager