Guest User

Guest User

  • Tech Writer
  • 2
  • 372

Excel et listview

Mar 23 2023 6:18 AM

Bonjour

Je voudrais afficher le contenu d'un fichier excel sur une listeview .

j'utilise c#. je suis bloqué je demande votre aide, merci

public partial class Form1 : Form
{
    public static Excel.Application? excelApp;
    public static Excel.Workbook? excelBook;
    public static Excel.Worksheet? excelSheet;
    public static Excel.Range? excelRange;

    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        excelApp = new Excel.Application();
        if (excelApp == null)
        {
            MessageBox.Show("Désolé, cette application nécessite Excel. Veuillez l'installer et réessayer.");
            Application.Exit();
        }
        else
        {
            try
            {
                excelBook = excelApp.Workbooks.Open(AppContext.BaseDirectory + "D:\\Cours_Informatique\\Session Mars-Mai-2023\\E14-Maintenance d'applications\\Liste\\ListePatineurs.xlsx");
                excelSheet = excelBook.Worksheets[1];
            }
            catch (Exception ex)
            {
                MessageBox.Show("Une erreur s'est produite.");
                Application.Exit();
            }
        }

    }

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        excelApp!.Quit();
        GC.Collect();
        GC.WaitForPendingFinalizers();


    }

    private void button1_Click(object sender, EventArgs e)
    {
        
        int lastRow = excelSheet!.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row;

        int lastCol = excelSheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Column;

        MessageBox.Show("le nombre de ligne: " + lastRow + "nombre colonne: " + lastCol);

        for (int i = 1; i < lastRow; i++)
        {
           

            for (int j = 0; j < lastCol; j++)
            {
               
            }
        }
    }

}

 


Answers (1)