Beispiel #1
0
        public static string CreateJsonText(ExcelGenerator configuration)
        {
            StringBuilder json = new StringBuilder();

            var keyList   = ExcelGenerator.Title_Row;
            var valueList = ExcelGenerator.Rows;

            json.AppendLine("{");
            json.AppendLine($"   \"{_fileName}\" : [");

            for (int i = 0; i < ExcelGenerator.Rows.Count; i++)
            {
                json.AppendLine("       {");
                for (int j = 0; j < ExcelGenerator.Title_Row[0].Count; j++)
                {
                    json.AppendLine($"          \"{keyList[0][j].ToString()}\" : \"{valueList[i][j].ToString()}\",");
                }
                json.Remove(json.Length - 3, 1);
                json.AppendLine("       },");
            }

            json.Remove(json.Length - 3, 1);
            json.AppendLine("   ]");
            json.AppendLine("}");
            return(json.ToString());
        }
Beispiel #2
0
        private void CreateXmlFile(ExcelGenerator configuration)
        {
            var xmlContent = CreateXmlText(configuration);

            File.WriteAllText(
                path: _outputPath,
                contents: xmlContent
                );
        }
Beispiel #3
0
        private void CreateCsvFile(ExcelGenerator configuration)
        {
            var csvContent = CreateCsvText(configuration);

            File.WriteAllText(
                path: _outputPath,
                contents: csvContent
                );
        }
Beispiel #4
0
        private void CreateJsonFile(ExcelGenerator configuration)
        {
            var jsonContent = CreateJsonText(configuration);

            File.WriteAllText(
                path: _outputPath,
                contents: jsonContent
                );
        }
Beispiel #5
0
        public void GenerateConfigurations(string validImportFile, List <string> outputFilePathList)
        {
            var excelGenerator = new ExcelGenerator();

            switch (Path.GetExtension(validImportFile))
            {
            case ".xlsx":
                OnStatusMessage($"Starting Excel Generator...");
                ExcelGenerator.Load(validImportFile, outputFilePathList);
                OnStatusMessage($"Finished to read the import file.");
                foreach (var outputPath in outputFilePathList)
                {
                    if (outputPath.Contains("json"))
                    {
                        OnStatusMessage($"Creating Json file...");
                        var jsonWriter = new JsonWriter(validImportFile, outputFilePathList, excelGenerator);
                        OnStatusMessage($"Created Json file : {outputPath}");
                    }
                    else if (outputPath.Contains("xml"))
                    {
                        OnStatusMessage($"Creating Xml file...");
                        var xmlWriter = new XmlWriter(validImportFile, outputFilePathList, excelGenerator);
                        OnStatusMessage($"Created Xml file : {outputPath}");
                    }
                    else if (outputPath.Contains("csv"))
                    {
                        OnStatusMessage($"Creating Csv file...");
                        var csvWriter = new CsvWriter(validImportFile, outputFilePathList, excelGenerator);
                        OnStatusMessage($"Created Csv file : {outputPath}");
                    }
                }
                break;

            case ".json":
                break;

            case ".xml":
                break;

            case ".csv":
                break;

            case ".sql":
                break;

            default:
                break;
            }
        }
Beispiel #6
0
 public CsvWriter(string validImportFile, List <string> outputFilePathList, ExcelGenerator configuration)
 {
     try
     {
         foreach (var path in outputFilePathList)
         {
             if (Path.GetExtension(path).Contains(FileFormat.csv.ToString()))
             {
                 _outputPath = path;
                 CreateCsvFile(configuration);
             }
         }
     }
     catch (Exception e)
     {
         Exceptions.Add(e);
     }
 }
Beispiel #7
0
 public XmlWriter(string validImportFile, List <string> outputFilePathList, ExcelGenerator configuration)
 {
     try
     {
         _fileName = Path.GetFileNameWithoutExtension(validImportFile);
         foreach (var path in outputFilePathList)
         {
             if (Path.GetExtension(path).Contains(FileFormat.xml.ToString()))
             {
                 _outputPath = path;
                 CreateXmlFile(configuration);
             }
         }
     }
     catch (Exception e)
     {
         Exceptions.Add(e);
     }
 }
Beispiel #8
0
        public static string CreateXmlText(ExcelGenerator configuration)
        {
            StringBuilder xml = new StringBuilder();

            var keyList   = ExcelGenerator.Title_Row;
            var valueList = ExcelGenerator.Rows;

            xml.AppendLine($"<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            xml.AppendLine($"<{_fileName}>");

            for (int i = 0; i < ExcelGenerator.Rows.Count; i++)
            {
                xml.AppendLine($"<{ExcelGenerator.WorkSheetName.Replace(" ", "-")}-{i+1}>");
                for (int j = 0; j < ExcelGenerator.Title_Row[0].Count; j++)
                {
                    xml.AppendLine($"   <{keyList[0][j].ToString().Replace(" ", "")}>{valueList[i][j].ToString()}</{keyList[0][j].ToString().Replace(" ", "")}>");
                }
                xml.AppendLine($"</{ExcelGenerator.WorkSheetName.Replace(" ", "-")}-{i+1}>");
            }
            xml.AppendLine($"</{_fileName}>");
            return(xml.ToString());
        }
Beispiel #9
0
        public static string CreateCsvText(ExcelGenerator configuration)
        {
            StringBuilder csv = new StringBuilder();

            var keyList   = ExcelGenerator.Title_Row;
            var valueList = ExcelGenerator.Rows;

            for (int i = 0; i < ExcelGenerator.Title_Row[0].Count; i++)
            {
                csv.Append($"{keyList[0][i].ToString()}, ");
            }
            csv.Remove(csv.Length - 2, 1);
            csv.AppendLine();
            for (int i = 0; i < ExcelGenerator.Rows.Count; i++)
            {
                for (int j = 0; j < ExcelGenerator.Title_Row[0].Count; j++)
                {
                    csv.Append($"{valueList[i][j].ToString()}, ");
                }
                csv.Remove(csv.Length - 2, 1);
                csv.AppendLine();
            }
            return(csv.ToString());
        }