This project has moved and is read-only. For the latest updates, please go here.

EPPlus search Worksheet by name

Dec 18, 2012 at 3:34 PM

Hello everybody

Now i'm using workBook.Worksheets.First() to open the first worksheet of a XLSX file.

There's a way to open a specify worksheet through a given string?

Thanks everybody

Alex

Dec 19, 2012 at 12:37 PM
Edited Dec 19, 2012 at 12:37 PM

Yes it is possible, Worksheets is indexed with string.

        public ExcelWorksheet GetWorksheet(string a_name)
        {
            return m_excelPackage.Workbook.Worksheets[a_name];
        }

 

Mateusz

Jan 29, 2013 at 10:07 PM

Or

public static void HideSheet(string srcFile, string sheet)
        {
            try
            {                        
                FileInfo file = new FileInfo(srcFile);
                ExcelPackage package = new ExcelPackage(file);
                ExcelWorksheet mySheet = package.Workbook.Worksheets.First(x => x.Name == sheet);
                mySheet.Hidden = eWorkSheetHidden.Hidden;                
                package.Save();               
            }
            catch (Exception ex)
            {
               
            }
        }
That way you can use things like x.Name.Comtains, etc.