Autofit Column in Excel with Aspose.Cells Cloud API – Quick Guide

This REST API automatically adjusts the width of a single column or a contiguous range of columns on an Excel worksheet.

Prerequisites

  • A valid Aspose Cloud subscription.
  • The Excel file must be uploaded to Aspose Cloud storage.
  • Correct folder and storageName values if the file is not in the root storage.

Authentication

All requests to the Aspose.Cells Cloud service require a JWT access token.

  1. Obtain a token – send a POST request to https://api.aspose.cloud/connect/token with your client ID and client secret.
  2. Include the token – add the header Authorization: Bearer <jwt token> to every API call.
  3. Required scopes – the token must contain the Cells scope to access worksheet operations.

REST API

POST https://api.aspose.cloud/v3.0/cells/{name}/worksheets/{sheetName}/autofitcolumns

Request parameters

Parameter Name Type Location Description
name string path The name of the Excel file.
sheetName string path The name of the worksheet.
firstColumn integer query Zero‑based index of the first column to autofit.
lastColumn integer query Zero‑based index of the last column to autofit.
autoFitterOptions object body Options that control the autofit behavior (see AutoFitterOptions).
firstRow integer query Zero‑based index of the first row considered when calculating column width.
lastRow integer query Zero‑based index of the last row considered when calculating column width.
folder string query The folder in storage where the file is located.
storageName string query The name of the storage service.

Error responses

HTTP Status Meaning Example JSON body
400 Invalid parameter(s) {"Code":400,"Message":"Invalid parameter 'firstColumn'."}
401 Unauthorized – missing or invalid JWT token {"Code":401,"Message":"Authorization failed."}
404 File or worksheet not found {"Code":404,"Message":"Worksheet 'Sheet1' not found."}
500 Internal server error {"Code":500,"Message":"An unexpected error occurred."}

The OpenAPI Specification defines a publicly accessible programming interface and lets you perform REST interactions directly from a web browser.

You can use the cURL command‑line tool to call Aspose.Cells Cloud services. The example below demonstrates how to invoke the autofit‑column endpoint.

Cloud SDK Family

Using an SDK is the fastest way to integrate the API into your application. SDKs handle low‑level details so you can focus on business logic. See the GitHub repository for the complete list of Aspose.Cells Cloud SDKs.

The following code examples demonstrate how to call the autofit‑column endpoint with various SDKs: