Excel is widely recognized for handling data analysis, reporting, and calculations. However, as spreadsheets grow in complexity, their file size can become challenging to manage. Large files consume storage, slow down systems, and create difficulties in sharing or collaborating. A reliable solution is to compress Excel workbooks to make them smaller and more manageable—without losing accuracy or functionality. In this tutorial, we’ll explore how to reduce Excel file size in C# .NET with the help of Aspose.Cells Cloud SDK and REST API.
API for Excel File Compression
One effective way to reduce workbook size is by leveraging Aspose.Cells Cloud API. This API simplifies Excel management tasks in the cloud, including file compression. It enables you to apply various compression algorithms and adjust compression levels, offering flexibility and precision. Since it’s a cloud-based solution, you can perform compression anywhere without installing additional software.
The Aspose.Cells Cloud SDK for .NET handles low-level operations, so you can focus on building features in your application. Now, in order to get started, search Aspose.Cells-Cloud from the NuGet package manager and then create a free account at Cloud Dashboard.
Shrink Excel Workbook using C#
Here’s a simple example demonstrating how to compress an Excel workbook in C# .NET:
var cellsApi = new CellsApi(config);
Create an object of cellsApi class where we pass the Configuration object as an argument.
var request = new PostCompressRequest(...);
Create request instance to compress the workbook.
var response = cellsApi.PostCompress(request);
Call the API to compress the Excel file and save the resultant file on cloud storage.
Compress XLS using cURL Commands
Alternatively, you can use cURL commands with Aspose.Cells Cloud API to automate workbook compression. This approach is helpful for scripting and batch workflows.
First, generate an access token using your client credentials:
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=XXXXXX-XXXXX-XXXXX-be35-ff5c3a6aa4a2&client_secret=XXXXXXXXXXX" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Then, execute the following cURL command to compress XLS to a smaller size:
curl -v "https://api.aspose.cloud/v3.0/cells/compress?CompressLevel=1&checkExcelRestriction=true" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: multipart/form-data" \
-d "File":{"excelFile"}
Replace:
{excelFile}
- name of input Excel file.{accessToken}
- Access token generated above.
- In order to download the resultant compressed file, try using
-o
argument.
Conclusion
Compressing Excel files is a practical way to optimize storage, reduce bandwidth usage, and enhance collaboration. Whether you use the .NET SDK or cURL commands, Aspose.Cells Cloud provides reliable tools to reduce Excel file size effectively. Try it out and see how much efficiency you can gain in your workflow.
Useful Resources
Recommended Articles
Please visit the following links to learn more about: