Example #1
0
        static void Main(string[] args)
        {
            var parser = new CommandLineParser(typeof(ExtractExcelDataParameters));
            ExtractExcelDataParameters arguments;

            try
            {
                arguments = (ExtractExcelDataParameters)parser.Parse(args);
            }
            catch (CommandLineArgumentException ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine();
                parser.WriteUsageToConsole();
                return;
            }

            if (arguments.File == null)
            {
                Console.WriteLine("Required parameter missing - File");
                return;
            }

            var excelData = new ExcelData(arguments.File);

            excelData.Open();

            if (arguments.List)
            {
                foreach (var sheetName in excelData.GetSheetNames())
                {
                    Console.WriteLine(sheetName);
                }
            }

            if (arguments.All)
            {
                foreach (var sheetName in excelData.GetSheetNames())
                {
                    WriteWorksheetToFile(excelData, sheetName, arguments.OutputPath);
                }
            }
            else if (arguments.Worksheet != null)
            {
                WriteWorksheetToFile(excelData, arguments.Worksheet, arguments.OutputPath);
            }

            excelData.Close();
        }