Table of Contents

  1. Overview

  2. Why Convert Excel to JSON?

  3. Key Benefits of Aspose.Cells LowCode JsonConverter

  4. Prerequisites

  5. Step-by-Step Conversion Guide

  6. Complete C# Example

  7. Performance Optimization Tips

  8. Common Issues & Troubleshooting

  9. Frequently Asked Questions (FAQs)

  10. Related Resources


Overview

The Aspose.Cells.LowCode JsonConverter simplifies converting Excel files (XLS, XLSX, XLSM) to JSON and JSON back into Excel. This functionality is particularly beneficial for developers working on RESTful API integrations, JavaScript dashboards, and web applications that require data exchange in JSON.


Why Convert Excel to JSON?

  • REST API Integration: Directly expose spreadsheet data through APIs.
  • Frontend Data Binding: Efficiently use JSON data in frontend frameworks and visualizations.
  • Cross-System Compatibility: JSON is widely accepted across diverse technology stacks, ensuring interoperability.

Key Benefits of Aspose.Cells LowCode JsonConverter

  • Minimal Coding: Quickly integrate conversion with a straightforward API.
  • Data Integrity: Maintains data accuracy during round-trip conversions.
  • Flexible File Handling: Supports direct file path or in-memory stream operations.
  • Easy Integration: Perfectly suited for .NET and serverless environments like Azure Functions.

Prerequisites

  1. Install the latest version of Aspose.Cells.LowCode via NuGet:

Install-Package Aspose.Cells.LowCode

  1. .NET 6.0 or newer.
  2. Import necessary namespaces:
using Aspose.Cells;
using Aspose.Cells.LowCode;

Step-by-Step Conversion Guide

Convert Excel to JSON

Convert Excel spreadsheets to structured JSON easily:

var loadOptions = new LowCodeLoadOptions { InputFile = "data.xlsx" };
var jsonOptions = new LowCodeSaveOptions { SaveFormat = SaveFormat.Json, OutputFile = "data.json" };
JsonConverter.Process(loadOptions, jsonOptions);

Convert JSON to Excel

Transform JSON data back into an Excel workbook:

var loadOptions = new LowCodeLoadOptions { InputFile = "data.json" };
var excelOptions = new LowCodeSaveOptions { SaveFormat = SaveFormat.Xlsx, OutputFile = "restored.xlsx" };
JsonConverter.Process(loadOptions, excelOptions);

Complete C# Example

Here’s a comprehensive example demonstrating both conversions:

using System;
using Aspose.Cells.LowCode;

namespace JsonConversionExample
{
    class Program
    {
        static void Main()
        {
            // Excel → JSON
            var excelToJsonLoadOpts = new LowCodeLoadOptions { InputFile = "report.xlsx" };
            var jsonSaveOpts = new LowCodeSaveOptions { SaveFormat = SaveFormat.Json, OutputFile = "report.json" };
            JsonConverter.Process(excelToJsonLoadOpts, jsonSaveOpts);
            Console.WriteLine("Excel to JSON conversion completed.");
            
            // JSON → Excel
            var jsonToExcelLoadOpts = new LowCodeLoadOptions { InputFile = "report.json" };
            var excelSaveOpts = new LowCodeSaveOptions { SaveFormat = SaveFormat.Xlsx, OutputFile = "report_converted.xlsx" };
            JsonConverter.Process(jsonToExcelLoadOpts, excelSaveOpts);
            Console.WriteLine("JSON to Excel conversion completed.");
        }
    }

} 

Performance Optimization Tips

  • Parallel Execution: Utilize .NET’s Parallel.ForEach for bulk conversions.
  • Large Files Handling: Break large JSON datasets into manageable chunks to optimize performance.
  • Stream-Based Conversion: Prefer stream operations for reduced disk I/O overhead.

Common Issues & Troubleshooting

Issue or ErrorPossible Solution
Invalid JSON formatEnsure the JSON input aligns with Aspose.Cells’ JSON structure.
File access issuesUse absolute paths or verify relative paths correctly.
Data discrepancies after conversionValidate JSON schema consistency and avoid manual alterations.

Frequently Asked Questions (FAQs)

Q1: Can I modify the default JSON structure? Yes. You can post-process JSON or use Aspose.Cells’ full API for more advanced customizations.

Q2: Is it suitable for cloud environments like Azure Functions? Yes, the converter supports stream-based conversions ideal for cloud deployments.

Q3: Do formulas get preserved in JSON? JSON exports cell values only; formulas require the full Aspose.Cells API for preservation.



More in this category