- Notifications
You must be signed in to change notification settings - Fork906
Adjust Row Height and Column Width to Contents
Francois Botha edited this pageFeb 26, 2018 ·3 revisions

varwb=newXLWorkbook();varws=wb.Worksheets.Add("Adjust To Contents");// Set some values with different font sizesws.Cell(1,1).Value="Tall Row";ws.Cell(1,1).Style.Font.FontSize=30;ws.Cell(2,1).Value="Very Wide Column";ws.Cell(2,1).Style.Font.FontSize=20;// Adjust column widthws.Column(1).AdjustToContents();// Adjust row heightsws.Rows(1,2).AdjustToContents();// You can also adjust all rows/columns in one shot// ws.Rows().AdjustToContents();// ws.Columns().AdjustToContents();// We'll now select which cells should be used for calculating the// column widths (same method applies for row heights)// Set the valuesws.Cell(4,2).Value="Width ignored because calling column.AdjustToContents(5, 7)";ws.Cell(5,2).Value="Short text";ws.Cell(6,2).Value="Width ignored because it's part of a merge";ws.Range(6,2,6,4).Merge();ws.Cell(7,2).Value="Width should adjust to this cell";ws.Cell(8,2).Value="Width ignored because calling column.AdjustToContents(5, 7)";// Adjust column widths only taking into account rows 5-7// (merged cells will be ignored)ws.Column(2).AdjustToContents(5,7);// You can also specify the row to start calculating the widths:// e.g. ws.Column(3).AdjustToContents(9);wb.SaveAs("AdjustToContents.xlsx");
- How do I deliver an Excel file in ASP.NET?
- Does it support Excel 2003 and prior formats (.xls)?
- How can I insert an image?
- Text with numbers are getting converted to numbers, what's up with that?
- How do I get the result of a formula?
- Data Types
- Creating Multiple Worksheets
- Organizing Sheets
- Loading and Modifying Files
- Using Lambda Expressions
- Cell Values
- Workbook Properties
- Using Formulas
- Evaluating Formulas
- Creating Rows And Columns Outlines
- Hide Unhide Rows And Columns
- Freeze Panes
- Copying Worksheets
- Using Hyperlinks
- Data Validation
- Hide Worksheets
- Sheet Protection
- Tab Colors
- Conditional Formatting
- Pivot Table example
- Sparklines
- Copying IEnumerable Collections
- Inserting Data
- Inserting Tables
- Adding DataTable as Worksheet
- Adding DataSet
- Styles - Alignment
- Styles - Border
- Styles - Fill
- Styles - Font
- Styles - NumberFormat
- NumberFormatId Lookup Table
- Style Worksheet
- Style Rows and Columns
- Using Default Styles
- Using Colors
- ClosedXML Predefined Colors
- Excel Indexed Colors
- Using Rich Text
- Using Phonetics
- Defining Ranges
- Merging Cells
- Clearing Ranges
- Deleting Ranges
- Multiple Ranges
- Shifting Ranges
- Transpose Ranges
- Named Ranges
- Accessing Named Ranges
- Copying Ranges
- Using Tables
- Sorting Data
- Selecting Cells and Ranges
- Row Height and Styles
- Selecting Rows
- Inserting Rows
- Inserting and Deleting Rows
- Adjust Row Height and Column Width to Contents
- Row Cells
- Column Width and Styles
- Selecting Columns
- Inserting Columns
- Inserting and Deleting Columns
- Adjust Row Height and Column Width to Contents
- Column Cells
- Pages Tab
- Paper Size Lookup Table
- Margins Tab
- Headers and Footers Tab
- Sheet Tab
- Print Areas and Page Breaks