This project has moved. For the latest updates, please go here.

How can i select 2 sheets i Excel ?

Sep 11, 2012 at 12:04 PM

Hi,

I want select 2 sheets.

And how can i display excel instance ?

 My code

Excel.Application excelApplication = new Excel.Application();
excelApplication.DisplayAlerts = false;
Excel.Workbook workBook = excelApplication.Workbooks.Open(@"D:\PROJETS.NET\BOVICAP-GCP\ApplicationPoubelle\Templates\Lait2013.xlsx");

Excel.Worksheet workSheet1 = (Excel.Worksheet)workBook.Worksheets["mysheet-1"];
Excel.Worksheet workSheet2 = (Excel.Worksheet)workBook.Worksheets["mysheet-2"];

List<Excel.Worksheet> sheetList = new List<Excel.Worksheet>();
sheetList.Add(workSheet1);
sheetList.Add(workSheet2);

workBook.Worksheets.SelectMany(f => sheetList);

Best regards

Sep 11, 2012 at 2:36 PM
Edited Sep 11, 2012 at 2:36 PM

Question: And how can i display excel instance ?

Solution

excelApplication.Visible = true;
Coordinator
Sep 12, 2012 at 1:16 PM

you can loop over the worksheets enumerator and select any worksheet step by step or you can use the Select method from the Sheets collection with a string array parameter. SelectMany is linq specific stuff and not helpfull here.

Sebastian