Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Adjust Row Height and Column Width to Contents

Francois Botha edited this pageFeb 26, 2018 ·3 revisions

AdjustToContents.jpg

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");

FAQ

Examples

Real world scenarios

Time Savers

Performance and Memory

Misc

Inserting Data/Tables

Styles

Ranges

Rows

Columns

Page Setup (Print Options)

AutoFilters

Comments

Dev docs

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp