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

Checking is the Workbook contain a worksheet? table? record?

Feb 13, 2012 at 4:50 PM
Edited Feb 13, 2012 at 4:50 PM

Hi,

How can i ensure the workbook contain a certain worksheet by giving its name?? and a worksheet contain specific table by giving its name???  and a table contain an empty record out of many,.. 

i am doing like this: 

 public int ExcelToDb(XLWorkbook wb)

        {
            List<game_question> cList = new List<game_question>();
         
            IXLWorksheets worksheets = wb.Worksheets;
            IXLWorksheet choices_worksheet;
            if (worksheets.TryGetWorksheet("Choices"out choices_worksheet))
            {
                try
                {
                    IXLTable cTable = choices_worksheet.Table("Choices");
                    cList = GetDistractorQuestionList(cTable, (int)QuestionType.Choices);
                }
                catch (Exception) { 
                    
                }
            }

Is there any way to implement simple checks like this,

if(wb.WorkSheet("choices")== true){
	if(worksheet.Table("choices") == true){
	//or hasTable() - hasWorksheet() etc
		
		if(!table.Row().empty){
	
		}
	}
}
Feb 13, 2012 at 5:35 PM

 

            IXLWorksheet ws;
            if (wb.Worksheets.TryGetWorksheet("choices", out ws))
            {
                // Do something with ws
            }

Or

 

            if (wb.Worksheets.Any(ws => ws.Name == "choices"))
            {
                var ws = wb.Worksheet("choices");
            }

Same goes for tables...

Feb 15, 2012 at 7:12 AM
Edited Feb 15, 2012 at 7:12 AM

Thanks