Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aspose-com-kb/e648479facc324d03f568be4f695df47 to your computer and use it in GitHub Desktop.
Save aspose-com-kb/e648479facc324d03f568be4f695df47 to your computer and use it in GitHub Desktop.
Autofit Rows and Columns in Excel using C#. For further details: https://kb.aspose.com/cells/net/autofit-rows-and-columns-in-excel-using-csharp/
using System;
using Aspose.Cells;
class Program
{
static void Main(string[] args) // Autofit Excel file using C#
{
new License().SetLicense("License.lic");
// Load the Excel file
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook("autofit.xlsx");
// Get reference of desired worksheet
Aspose.Cells.Worksheet worksheet = workbook.Worksheets[0];
// Auto fit the columns and rows
worksheet.AutoFitRows(); worksheet.AutoFitColumns();
// Save workbook
workbook.Save("autofit-excel.xlsx");
Console.WriteLine("Done");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment