Table of Contents
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
- Install the latest version of Aspose.Cells.LowCode via NuGet:
Install-Package Aspose.Cells.LowCode
- .NET 6.0 or newer.
- 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 Error | Possible Solution |
---|---|
Invalid JSON format | Ensure the JSON input aligns with Aspose.Cells’ JSON structure. |
File access issues | Use absolute paths or verify relative paths correctly. |
Data discrepancies after conversion | Validate 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.
Related Resources
More in this category
- How to Automate Excel in .NET with Aspose.Cells.LowCode
- Convert Excel to Images Using Aspose.Cells for .NET Plugin
- How to Convert Excel to Text Formats (CSV, TSV, XML) with Aspose.Cells for .NET
- How to Lock and Protect Excel Spreadsheets with Aspose.Cells for .NET
- Excel to PDF: Aspose.Cells PDF Converter Plugin for .NET