Skip to content

Instantly share code, notes, and snippets.

Code to Set Width of Cell in Excel using C#. A detailed article is available here for further description: https://kb.aspose.com/cells/net/how-to-set-width-of-cell-in-excel-using-csharp/
using Aspose.Cells;
namespace SetWidthOfCellInExcelUsingCSharp
{
class Program
{
static void Main(string[] args) // Main function to set width of cell in CSharp
{
// Instantiate the license to remove trial version watermark in the output Excel file
Aspose.Cells.License licForCells= new Aspose.Cells.License();
licForCells.SetLicense("Aspose.Svg.lic");
// Create a workbook class object to set column width
Workbook wb = new Workbook();
// Access the first worksheet from the default collection of worksheets
Worksheet ws = wb.Worksheets[0];
// Set the column width to 20.0
ws.Cells.SetColumnWidth(1, 20.0);
// Saving the Excel file having specified column width
wb.Save("output.xlsx");
System.Console.WriteLine("Done");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment