示例#1
0
        public async Task <IActionResult> CreateDocFile(string typeDocument)
        {
            switch (typeDocument)
            {
            case ".docx":
            {
                var model = await _serviceManager.Staff.StaffsList();

                int          countRecord = model.Count();
                var          document    = new DocParse();
                MemoryStream bais        = new MemoryStream(document.CreateTableDoc(model, countRecord).ToArray());
                string       file_type   = "application/docx";
                string       file_name   = "prikaz.docx";
                return(File(bais, file_type, file_name));
            }

            case ".xlsx":
            {
                var model = await _serviceManager.Staff.StaffsList();

                int          countRecord = model.Count();
                var          document    = new XlsxParser();
                MemoryStream bais        = new MemoryStream(document.CreateTableXlsx(model, countRecord).ToArray());
                string       file_type   = "application/xlsx";
                string       file_name   = "prikaz.xlsx";
                return(File(bais, file_type, file_name));
            }
            }
            return(View());
        }
示例#2
0
        IEnumerator Start()
        {
            var ftc = new FieldTypeConverter();

            Application.logMessageReceived += _HandleLog;
            Debug.LogWarning("This example works in editor and standalone.");
            _RefreshConsole();
            var patchName = "XlsxParser_04_Patch";

            _CopyXlsxFromResources("XlsxParser_04");
            _CopyXlsxFromResources(patchName);
            _myObjects = new Dictionary <string, Object3D>();
            var parser = new XlsxParser(
                "res://XlsxParser_04".SetFieldTypeConverter(ftc)
                );

            yield return(parser.coroutine);

            var table = parser.dataSet["Object3D"];
            var n     = 0;

            table.Populate(_myObjects, () => {
                var inst = Object3D.Create();
                var x    = 3.0F * (n % 5);
                var z    = 3.0F * (n / 5);
                ++n;
                inst.transform.position = new Vector3(x, 3, z);
                return(inst);
            }, 0);

            var path = _home + "/" + patchName + ".xlsx";

            StartCoroutine(Watch(path, _OnDataSetUpdated));
        }
示例#3
0
        public static IEnumerator Watch(
            string path,
            System.Action <DataSet, XlsxParser.Errors> onDataSetUpdated)
        {
            var ftc           = new FieldTypeConverter();
            var lastWriteTime = new System.DateTime(
                1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc
                );

            while (File.Exists(path))
            {
                yield return(null);

#if (!UNITY_WEBPLAYER)
                var wt = File.GetLastWriteTimeUtc(path);
#else
                var wt = lastWriteTime;
#endif
                if (wt <= lastWriteTime)
                {
                    continue;
                }
                lastWriteTime = wt;
                var parser = new XlsxParser(path.SetFieldTypeConverter(ftc));
                while (!parser.isDone)
                {
                    yield return(null);
                }
                if (onDataSetUpdated != null)
                {
                    onDataSetUpdated(parser.dataSet, parser.errors);
                }
            }
        }
        public void Create_OK()
        {
            var bytes = Properties.Resources.Eksempel_Liste;

            using (var parser = new XlsxParser(bytes))
            { }
        }
 public void GetData_MissingColumnValue_EqualRowLength()
 {
     using (var parser = new XlsxParser(Properties.Resources.Eksempel_Liste_MissingColumn))
     {
         var data    = parser.GetData();
         var lengths = data.Select(d => d.Length);
         Assert.AreEqual(1, lengths.Distinct().Count());
         foreach (var d in data)
         {
             Console.WriteLine(d.Length);
         }
     }
 }
示例#6
0
        private static void Run(CommandLineOptions options)
        {
            try
            {
                var looParser  = new LooParser();
                var xlsxParser = new XlsxParser();
                switch (options.File)
                {
                case var xlsxFile when Path.GetExtension(options.File)
                    .Equals(XlsxExtension, StringComparison.CurrentCultureIgnoreCase)
                    :     //if xlsxl file -> convert to loo
                    foreach (var language in Enum.GetValues(typeof(ParserLanguage)).Cast <ParserLanguage>())
                    {
                        Console.WriteLine($"Preparing loo file for {language} language.");
                        var xlsxLines = xlsxParser.LoadXlsFile(xlsxFile, options.FormatFile, language);

                        Console.WriteLine($"{xlsxLines.Count} keys found for {language} language.");
                        var looFilename  = options.CreateLanguageFiles ? $"locdirect_{language.ToString().ToLower()}{LooExtension}" : $"{((ParserLanguageShort) language).ToString().ToLower()}\\locdirect_english{LooExtension}";
                        var looDirectory = Path.GetDirectoryName(looFilename);

                        if (!string.IsNullOrWhiteSpace(looDirectory) && !Directory.Exists(looDirectory))
                        {
                            Directory.CreateDirectory(looDirectory);
                        }
                        looParser.SaveLooFile(xlsxLines, looFilename);
                        Console.WriteLine($"Saved {looFilename} for {language} language.");
                    }

                    break;

                case var looFile when Path.GetExtension(options.File)
                    .Equals(LooExtension, StringComparison.CurrentCultureIgnoreCase)
                    :     //if loo file -> convert to xlsx
                    Console.WriteLine("Converting .loo file to .xslx");

                    var looLines     = looParser.LoadLooFile(looFile);
                    var xlsxFilename = Path.GetFileNameWithoutExtension(looFile) + XlsxExtension;
                    xlsxParser.SaveXlsFile(looLines, xlsxFilename);
                    Console.WriteLine($"Saved {xlsxFilename}.");
                    break;

                default:
                    Console.WriteLine("Invalid file type supplied. Only .loo and .xlsx are valid.");
                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occured: {0}", e);
            }
        }
示例#7
0
        private static void Main(string[] args)
        {
            try
            {
                if (args.Length <= 1) //If no file was supplied exit.
                {
                    PrintHelp();
                }
                else
                {
                    var file       = args[0];
                    var codePage   = int.Parse(args[1]);
                    var looParser  = new LooParser();
                    var xlsxParser = new XlsxParser();
                    switch (file)
                    {
                    case var xlsxFile when Path.GetExtension(file)
                        .Equals(XlsxExtension, StringComparison.CurrentCultureIgnoreCase)
                        : //if xlsxl file -> convert to loo
                        var xlsxLines = xlsxParser.LoadXlsFile(xlsxFile, args.Length > 1 ? args[2] : null);

                        looParser.SaveLooFile(xlsxLines, Path.GetFileNameWithoutExtension(xlsxFile) + LooExtension,
                                              codePage);
                        break;

                    case var looFile when Path.GetExtension(file)
                        .Equals(LooExtension, StringComparison.CurrentCultureIgnoreCase)
                        : //if loo file -> convert to xlsx
                        var looLines = looParser.LoadLooFile(looFile, codePage);

                        xlsxParser.SaveXlsFile(looLines, Path.GetFileNameWithoutExtension(looFile) + XlsxExtension);
                        break;

                    default:
                        PrintHelp();
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                PrintHelp();
                throw e;
            }
        }
示例#8
0
        private string _GetColoredParserErrors(XlsxParser parser)
        {
            if (parser.errors.count == 0)
            {
                return(parser.errors.ToString());
            }
            var sb        = new StringBuilder();
            var colorTags = new string[] {
                "<color=red>", "<color=magenta>"
            };
            var errors = parser.errors;

            for (var n = 0; n < errors.count; ++n)
            {
                sb.Append(colorTags[n % colorTags.Length]);
                sb.AppendLine(errors[n] + "</color>");
            }
            return(sb.ToString());
        }
        IEnumerator Start()
        {
            var ftc    = new FieldTypeConverter();
            var parser = new XlsxParser(
                "res://XlsxParser_02".SetFieldTypeConverter(ftc)
                );

            yield return(parser.coroutine);

            if (parser.errors.count > 0)
            {
                Debug.LogWarning(parser.errors);
                yield break;
            }
            var table = parser.dataSet["Object3D"];

            DataTable.Warnings warnings = null;
            warnings = table.GetObjectMappingWarnings <Object3D>();
            if (warnings.count > 0)
            {
                Debug.LogWarning(warnings);
            }
            _myObjects = new Dictionary <string, Object3D>();
            var n = 0;

            // If key field is duplicated, will be overwritten.
            // To ensure key unique, use data validation in xlsx editor.
            // If keyFieldIndex is negative, key is set row order.
            warnings = table.Populate(_myObjects, () => {
                var inst = Object3D.Create();
                var x    = 3.0F * (n % 3);
                var z    = 3.0F * (n / 3);
                ++n;
                inst.transform.position = new Vector3(x, 3, z);
                return(inst);
            }, 0);
            if (warnings.count > 0)
            {
                Debug.LogWarning(warnings);
            }
        }
示例#10
0
        private Dictionary <string, List <UI.Text> > _CreateResults(
            XlsxParser parser)
        {
            var results = new Dictionary <string, List <UI.Text> >();

            results[""] = _CreateResult(""
                                        + "\nElapsedTime: " + parser.elapsedTime + "\n\n"
                                        + _GetColoredParserErrors(parser)
                                        );
            var colorTags = new string[] {
                "<color=olive>", "<color=teal>"
            };

            foreach (var table in parser.dataSet)
            {
                var sb = new StringBuilder();
                sb.AppendLine(_GetFieldNames(table));
                sb.AppendLine(_GetFieldNamesForWriter(table));
                var padding = ("" + table.rowCount).Length;
                for (var r = 0; r < table.rowCount; ++r)
                {
                    sb.Append("[" + ("" + r).PadLeft(padding) + "]: ");
                    sb.Append(colorTags[r % colorTags.Length]);
                    for (var c = 0; c < table.schema.fieldCount; ++c)
                    {
                        if (table[r][c] == null)
                        {
                            sb.Append("null, ");
                        }
                        else
                        {
                            sb.Append(table.GetCellValue <string>(r, c) + ", ");
                        }
                    }
                    sb.AppendLine("</color>");
                }
                results[table.name] = _CreateResult(sb.ToString());
            }
            return(results);
        }
 public void AddColumn_ContainsNewColumn()
 {
     byte[] generatedBytes;
     using (var parser = new XlsxParser(Properties.Resources.Eksempel_Liste))
     {
         if (!parser.ContentsTable.Columns.Contains("PNR"))
         {
             parser.ContentsTable.Columns.Add("PNR", typeof(string));
         }
         int i = 1;
         foreach (DataRow row in parser.ContentsTable.Rows)
         {
             row["PNR"] = i++.ToString().PadLeft(10, '0');
         }
         generatedBytes = parser.SerializeContents();
     }
     using (var newParser = new XlsxParser(generatedBytes))
     {
         Assert.IsTrue(newParser.GetColumnNames().Contains("PNR"));
     }
     File.WriteAllBytes("AddColumn_ContainsNewColumn.xlsx", generatedBytes);
 }
示例#12
0
        private IEnumerator _LoadXlsxFiles(params XlsxRequest[] requests)
        {
            yield return(null);

            // You do not need to use the 'using' block.
            // because parser calls 'Dispose()' when completes work.
            var parser = new XlsxParser(requests);
            // yield return parser.coroutine;
            var loadingText = loadingPanel.GetComponentInChildren <UI.Text>();
            var loadingIcon = @"|/-\";
            var m           = 0;

            while (!parser.isDone)
            {
                loadingText.text = "" + loadingIcon[m];
                m = (m + 1) % loadingIcon.Length;
                loadingText.text += "\n" + (int)(parser.progress * 100) + "%";
                yield return(new WaitForSeconds(0.25F));
            }
            _results = _CreateResults(parser);
            _ShowResult("");
            _RefreshToggles(parser.dataSet);
            loadingPanel.SetActive(false);
        }