Пример #1
0
        private void saveExcel_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
        {
            string name = saveExcel.FileName;
            // Get JSON text
            JObject obj = JObject.Parse(jsonContainer.Text);

            obj.AddFirst(new JProperty("name", rootName));
            string jsonString = "[" + obj.ToString() + "]";

            // Create a Workbook object
            Workbook  workbook  = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            // Set Styles
            CellsFactory factory = new CellsFactory();
            Style        style   = factory.CreateStyle();

            style.HorizontalAlignment = TextAlignmentType.Center;
            style.Font.Color          = System.Drawing.Color.BlueViolet;
            style.Font.IsBold         = true;

            // Set JsonLayoutOptions
            JsonLayoutOptions options = new JsonLayoutOptions();

            options.ConvertNumericOrDate = true;
            options.TitleStyle           = style;
            options.ArrayAsTable         = true;

            // Import JSON Data
            JsonUtility.ImportData(jsonString, worksheet.Cells, 0, 0, options);

            // Save Excel file
            workbook.Save(@name);
        }
Пример #2
0
        public static void Run()
        {
            // ExStart:1
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

            //Output directory
            string outputDir = RunExamples.Get_OutputDirectory();

            // Read JSON file
            string str = File.ReadAllText(sourceDir + "SampleJson.json");

            // Create empty workbook
            Workbook workbook = new Workbook();

            // Get Cells
            Cells cells = workbook.Worksheets[0].Cells;

            // Set JsonLayoutOptions
            JsonLayoutOptions importOptions = new JsonLayoutOptions();

            importOptions.ConvertNumericOrDate = true;
            importOptions.ArrayAsTable         = true;
            importOptions.IgnoreArrayTitle     = true;
            importOptions.IgnoreObjectTitle    = true;
            JsonUtility.ImportData(str, cells, 0, 0, importOptions);

            // Save Workbook
            workbook.Save(outputDir + @"SampleJson_out.csv");
            // ExEnd:1

            Console.WriteLine("ConvertJsonToCsv executed successfully.");
        }
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Instantiating a Workbook object
            Workbook  workbook  = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            // Read File
            string jsonInput = File.ReadAllText(dataDir + "Test.json");

            // Set Styles
            CellsFactory factory = new CellsFactory();
            Style        style   = factory.CreateStyle();

            style.HorizontalAlignment = TextAlignmentType.Center;
            style.Font.Color          = System.Drawing.Color.BlueViolet;
            style.Font.IsBold         = true;

            // Set JsonLayoutOptions
            JsonLayoutOptions options = new JsonLayoutOptions();

            options.TitleStyle   = style;
            options.ArrayAsTable = true;

            // Import JSON Data
            JsonUtility.ImportData(jsonInput, worksheet.Cells, 0, 0, options);

            // Save Excel file
            workbook.Save(dataDir + "ImportingFromJson.out.xlsx");
            // ExEnd:1
        }
Пример #4
0
        static void Main(string[] args)
        {
            List <FileDetails> filesList = new List <FileDetails>();

            DirectoryInfo directoryInfo = new DirectoryInfo(@"C:\Users\AlKhalilAlMaamari\Documents\Data Managment\Backup");

            FileInfo[] fileInfo = directoryInfo.GetFiles();

            FileDetails fi = new FileDetails();

            foreach (FileInfo f in fileInfo)
            {
                FileInfo file         = new FileInfo(f.Name);
                string   filePath     = file.FullName;
                string   fileHashCode = fi.GetHashCode(@"C:\Users\AlKhalilAlMaamari\Documents\Data Managment\Backup\" + f.Name, new SHA512Cng());

                filesList.Add(new FileDetails {
                    FileName = f.Name, FilePath = filePath, FileSize = f.Length / 1024, FileHash = fileHashCode
                });
            }

            var json = System.Text.Json.JsonSerializer.Serialize(filesList);


            File.WriteAllText(@"C:\Users\AlKhalilAlMaamari\Documents\Data Managment\Json\Files Info.txt", json);
            string jsonString = File.ReadAllText(@"C:\Users\AlKhalilAlMaamari\Documents\Data Managment\Json\Files Info.txt");
            var    filesList2 = JsonConvert.DeserializeObject <List <FileDetails> >(jsonString);

            foreach (var a in filesList2)
            {
                Console.WriteLine(a.FileName + " " + a.FilePath + " " + a.FileSize + " " + a.FileHash);
            }

            // Create a Workbook object
            Workbook  workbook  = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            // Read JSON File
            string jsonInput = File.ReadAllText(@"C:\Users\AlKhalilAlMaamari\Documents\Data Managment\Json\Files Info.txt");

            // Set JsonLayoutOptions
            JsonLayoutOptions options = new JsonLayoutOptions();

            options.ArrayAsTable = true;

            // Import JSON Data
            JsonUtility.ImportData(jsonInput, worksheet.Cells, 0, 0, options);

            // Save Excel file
            workbook.Save("Import-Data-JSON-To-Excel.xlsx");
            workbook.Save("Import-Data-JSON-To-Excel.csv");
        }
Пример #5
0
        public string uploadFile(Model model)
        {
            Workbook workbook = new Workbook();

            Worksheet worksheet = workbook.Worksheets[0];


            // Set JsonLayoutOptions
            JsonLayoutOptions options = new JsonLayoutOptions();

            options.ArrayAsTable = true;

            // Import JSON Data
            Aspose.Cells.Utility.JsonUtility.ImportData(model.jsonString, worksheet.Cells, 0, 0, options);

            // Save Excel file
            string excelfile = DateTime.Now.ToFileTime() + ".xlsx";

            workbook.Save(excelfile);


            ClientContext context = new ClientContext(siteUrl);

            SecureString passWord = new SecureString();

            foreach (var c in password)
            {
                passWord.AppendChar(c);
            }
            context.Credentials = new SharePointOnlineCredentials(userName, passWord);
            Web site = context.Web;

            //Get the required RootFolder
            string barRootFolderRelativeUrl = "Shared Documents/ExportExcel";
            Folder barFolder = site.GetFolderByServerRelativeUrl(barRootFolderRelativeUrl);

            //Add file to new Folder
            FileCreationInformation newFile = new FileCreationInformation {
                Content = System.IO.File.ReadAllBytes(excelfile), Url = Path.GetFileName(excelfile), Overwrite = true
            };

            barFolder.Files.Add(newFile);
            barFolder.Update();

            context.ExecuteQuery();

            //Return the URL of the new uploaded file
            string newUrl = siteUrl + barRootFolderRelativeUrl + "/" + Path.GetFileName(excelfile);

            return(newUrl);
        }
        //////* Calculo de operaciones

        public void TamblaDeSimbolosFase3(List <KeyValuePair <string, string> > tokensAceptados)
        {        //5
            Cadenas = TextValidation.Cadenas;
            AbrirUnAmbito("Global");
            PilaDeTipoDeSentencia.Push("Global");
            var cadena = "";

            for (int i = 0; i < tokensAceptados.Count; i++)
            {
                cadena += $" {tokensAceptados[i].Value}";
                cadena  = cadena.Trim();
            }

            var actual = 0;

            while (cadena != "")
            {
                var aux = "";
                while (tokensAceptados[actual].Key != ";" && tokensAceptados[actual].Key != ")" && tokensAceptados[actual].Key != "{" && tokensAceptados[actual].Key != "}")
                {
                    aux += $" {tokensAceptados[actual].Value}";
                    aux  = aux.Trim();
                    actual++;
                }
                if (tokensAceptados[actual].Key == "{")
                {
                    if (aux == "")
                    {                    //solo encontro la llave
                        cadena = cadena.Remove(0, cadena.IndexOf("{") + 1).Trim();
                    }
                    else
                    {
                        IdentificarDeclaracion(aux);

                        cadena = QuitarTokensDeLaCadena(cadena, aux + " {");
                    }
                    scoopingLevel++;
                    ScoopingActual++;
                    actual++;
                }
                else if (tokensAceptados[actual].Key == "}")
                {
                    if (aux == "")
                    {                    //solo encontro la llave
                        cadena = cadena.Remove(0, cadena.IndexOf("}") + 1).Trim();
                    }
                    else
                    {
                        IdentificarDeclaracion(aux);

                        cadena = QuitarTokensDeLaCadena(cadena, aux + " {");
                    }
                    scoopingLevel++;
                    ScoopingActual--;
                    //cerramos un ambito y lo sacamos de la pila
                    if ((PilaDeAmbitos.Peek() == "Global"))
                    {
                    }
                    else
                    {
                        RegistroDeAmbitos[PilaDeAmbitos.Peek()].Accesible = false;
                        PilaDeAmbitos.Pop();
                        PilaDeTipoDeSentencia.Pop();
                    }
                    actual++;
                }
                else
                {
                    if (aux == ";")
                    {
                        cadena = cadena.Remove(0, cadena.IndexOf(";") + 1).Trim();
                    }
                    else
                    {
                        aux += $" {tokensAceptados[actual].Value}";
                        aux  = aux.Trim();
                        actual++;
                        IdentificarDeclaracion(aux);

                        cadena = QuitarTokensDeLaCadena(cadena, aux);
                    }
                }
            }
            var xd = JsonConvert.SerializeObject(RegistroDeAmbitos);
            // Create a Workbook object
            Workbook  workbook  = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            // Read JSON File
            string jsonInput = xd;

            // Set JsonLayoutOptions
            JsonLayoutOptions options = new JsonLayoutOptions();

            options.ArrayAsTable = true;

            // Import JSON Data
            JsonUtility.ImportData(jsonInput, worksheet.Cells, 0, 0, options);

            // Save Excel file
            workbook.Save("TablaDeSimbolos.xlsx");
        }