Lecture d'un ComboBox Excel à partir d'une application C#
Bonjour,
Ça fait des heures et des heures que j'essaie de trouver un moyen d'accéder les valeurs d'un combobox créé sur une feuille excel à partir de mon programme C#.
Voici mon code simplifié :
Code:
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
| using System;
using Excel;
using Microsoft.Vbe.Interop.Forms;
----------------------------------------------
Excel.Application app = new Excel.Application();
Excel.Workbook workBook = app.Workbooks.Open("C:\test.xls", 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 0, 0);
Excel.Sheets wsFeuillesALire = workBook.Worksheets;
foreach (Excel.Worksheet workSheet in wsFeuillesALire)
{
if (workSheet.Name.Equals("Offre"))
{
Excel.OLEObjects oleObjects1 = (Excel.OLEObjects)workSheet.OLEObjects(Type.Missing);
foreach (Excel.OLEObject ole in oleObjects1)
{
Microsoft.Vbe.Interop.Forms.ComboBox newBox = (Microsoft.Vbe.Interop.Forms.ComboBox)(((Excel.OLEObject)ole).Object);
Console.WriteLine(newBox.SelText.ToString());
}
}
} |
Quand j'exécute ça, j'obiens une erreur de type System.AccessViolationException. Vraiment, je n'y comprends rien et ça me bloque littéralement dans mon travail.
Si quelqu'un pouvait m'aider, ce serait très apprécié !
Merci beaucoup !