Working with Autofit on an Excel Worksheet – Aspose.Cells Cloud API
Contents
[
Hide
]
Working with autofit on an Excel worksheet
- How to autoFit a column on an Excel worksheet.
- How to autoFit columns on an Excel worksheet.
- How to autoFit a row on an Excel worksheet.
- How to autoFit rows on an Excel worksheet.
Prerequisites
Before using the Autofit operations you must have:
- An Aspose.Cells Cloud account with a valid Client Id and Client Secret.
- A workbook uploaded to Aspose Cloud storage (or accessible via a public URL).
- The worksheet name you intend to modify.
API Reference
| Operation | HTTP Method | Endpoint | Required Parameters | Request Body | Sample Response | Status Codes |
|---|---|---|---|---|---|---|
| AutoFit a column | POST | /cells/worksheets/{sheetName}/autofit/column |
sheetName (path) columnIndex (query) |
none | { "code": 200, "status": "OK", "message": "Column autofitted." } |
200, 400, 401, 404, 500 |
| AutoFit columns | POST | /cells/worksheets/{sheetName}/autofit/columns |
sheetName (path) startColumn, endColumn (query) |
none | { "code": 200, "status": "OK", "message": "Columns autofitted." } |
200, 400, 401, 404, 500 |
| AutoFit a row | POST | /cells/worksheets/{sheetName}/autofit/row |
sheetName (path) rowIndex (query) |
none | { "code": 200, "status": "OK", "message": "Row autofitted." } |
200, 400, 401, 404, 500 |
| AutoFit rows | POST | /cells/worksheets/{sheetName}/autofit/rows |
sheetName (path) startRow, endRow (query) |
none | { "code": 200, "status": "OK", "message": "Rows autofitted." } |
200, 400, 401, 404, 500 |
Code Samples
cURL
curl -X POST "https://api.aspose.cloud/v3.0/cells/worksheets/MySheet/autofit/columns?startColumn=0&endColumn=5" \
-H "Authorization: Bearer {access_token}" \
-H "Content-Type: application/json"
.NET (C#)
using Aspose.Cells.Cloud.SDK.Api;
using Aspose.Cells.Cloud.SDK.Model;
// Authenticate
var apiInstance = new CellsApi("{client_id}", "{client_secret}");
// Call Autofit columns
var response = apiInstance.PostWorksheetAutofitColumns(
name: "Workbook.xlsx",
sheetName: "Sheet1",
startColumn: 0,
endColumn: 5,
folder: "",
storageName: ""
);
Console.WriteLine(response.Status);
Java
import com.aspose.cloud.cells.api.CellsApi;
import com.aspose.cloud.cells.model.*;
CellsApi api = new CellsApi("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET");
// Autofit rows
PostWorksheetAutofitRowsResponse resp = api.postWorksheetAutofitRows(
"Workbook.xlsx",
"Sheet1",
0, // startRow
10, // endRow
"", // folder
"" // storageName
);
System.out.println(resp.getStatus());
Python
from asposecellscloud import CellsApi, ApiClient, Configuration
config = Configuration()
config.client_id = "YOUR_CLIENT_ID"
config.client_secret = "YOUR_CLIENT_SECRET"
api_client = ApiClient(configuration=config)
api = CellsApi(api_client)
# Autofit a single column
response = api.post_worksheet_autofit_column(
name="Workbook.xlsx",
sheet_name="Sheet1",
column_index=2,
folder="",
storage_name=""
)
print(response.status)
These snippets demonstrate how to:
- Authenticate with Aspose.Cells Cloud using your Client Id and Client Secret.
- Call the appropriate Autofit endpoint for columns or rows.
- Process the response, which confirms that the operation succeeded.
Next Steps
After the Autofit call completes, you can download the updated workbook:
curl -X GET "https://api.aspose.cloud/v3.0/cells/Workbook.xlsx" \
-H "Authorization: Bearer {access_token}" \
-o UpdatedWorkbook.xlsx
Feel free to adjust the startColumn, endColumn, startRow, and endRow parameters to target specific ranges.