Aspose.Plugins.AsposeVSOpenXML.Form1.BTN_Export_Click C# (CSharp) Method

BTN_Export_Click() private method

private BTN_Export_Click ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
return void
        private void BTN_Export_Click(object sender, EventArgs e)
        {
           //Creating a file stream containing the Excel file to be opened
           FileStream fstream = new FileStream(FOD_OpenFile.FileName, FileMode.Open);

           //Instantiating a Workbook object
           //Opening the Excel file through the file stream
           Workbook workbook = new Workbook(fstream);

           //Accessing the first worksheet in the Excel file
           Worksheet worksheet = workbook.Worksheets[0];

           //Exporting the contents of 2 rows and 2 columns starting from 1st cell to DataTable
           DataTable dataTable = worksheet.Cells.ExportDataTable(0, 0,2, 2, true);

           //Binding the DataTable with DataGrid

           dataGridView1.DataSource = dataTable;

           //Closing the file stream to free all resources
           fstream.Close();
        }