Exemplo n.º 1
0
        static void RunOptions(Options options)
        {
            if (!Directory.Exists(options.InputDir))
            {
                return;
            }

            LogHandler logHandler = new LogHandler((type, id, msg) =>
            {
                string msgType = "Info";
                Color color    = Color.White;

                if (type == LogType.Error)
                {
                    msgType = "Error";
                    color   = Color.Red;
                }
                else if (type == LogType.Warning)
                {
                    msgType = "Warning";
                    color   = Color.Yellow;
                }

                Colorful.Console.WriteLine($"[{msgType}]    [{id}]  {msg}", color);
            });

            WorkbookReader reader = new WorkbookReader(logHandler);

            TypeContext context = new TypeContext();

            context.Add(typeof(LogHandler), logHandler);

            Workbook[] workbooks = reader.ReadExcelFromDir(options.InputDir);
            if (workbooks != null && workbooks.Length > 0)
            {
                foreach (var workbook in workbooks)
                {
                    string dir = $"{options.OutputDir}/{workbook.Name}";
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    bool result = workbook.Verify(context);
                    if (result)
                    {
                        for (int i = 0; i < workbook.SheetCount; ++i)
                        {
                            Sheet sheet = workbook.GetSheeetByIndex(i);
                            if (options.Format == OutputFormat.Json)
                            {
                                JsonWriter.WriteTo(sheet, dir);
                            }
                            else if (options.Format == OutputFormat.Ndb)
                            {
                                NdbWriter.WriteTo(sheet, dir);
                            }
                            else if (options.Format == OutputFormat.Lua)
                            {
                                LuaWriter.WriteTo(sheet, dir);
                            }
                        }
                    }
                }
            }
            context.Clear();
        }