FlexGrid for WinForms | ComponentOne
C1.Win.C1FlexGrid Namespace / Extensions Class / LoadExcelSheetNames Method / LoadExcelSheetNames(C1FlexGridBase,String) Method
C1FlexGridBase instance to which a file will be loaded.
Name of the Excel file, including the path.
Example

In This Topic
    LoadExcelSheetNames(C1FlexGridBase,String) Method
    In This Topic
    Gets a list with the names of the worksheets in a Microsoft Excel (.XLS) file.
    Syntax
    'Declaration
     
    
    Public Overloads Shared Function LoadExcelSheetNames( _
       ByVal grid As C1FlexGridBase, _
       ByVal fileName As String _
    ) As String()
    public static string[] LoadExcelSheetNames( 
       C1FlexGridBase grid,
       string fileName
    )

    Parameters

    grid
    C1FlexGridBase instance to which a file will be loaded.
    fileName
    Name of the Excel file, including the path.

    Return Value

    An array containing the names of the worksheets defined in the file.
    Remarks
    This method is used to obtain a list of sheet names that can later be used to load and save specific sheets using the LoadExcel(C1FlexGridBase,String,String,FileFlags) and SaveExcel(C1FlexGridBase,String,String,FileFlags,PrinterSettings) methods.
    Example
    The code below loads all sheets in an Excel workbook into a collection of grids in a TabControl:
    // clear tabControl
    tabControl.TabPages.Clear();
                
    // load sheet names
    string fileName = "c:\book1.xls";
    string[] sheets = _flexGrid.LoadExcelSheetNames(fileName);
                
    // load each sheet
    foreach (string sheetName in sheets)
    {
      // create a new grid for this sheet
      C1FlexGrid flex = new C1FlexGrid();
      flex.Dock = DockStyle.Fill;
      
      // load sheet into new grid
      flex.LoadExcel(fileName, sheetName);
      
      // add grid to the tabControl
      TabPage page = new TabPage();
      page.Controls.Add(flex);
      page.Text = sheetName;
      tabControl.TabPages.Add(page);
    }
    See Also