EasyXLS™ library provides the necessary methods that enable you to easily set row height and column width for Excel spreadsheets. It also allows you to read the row height or column width, if necessary.
The row height and column width can be set for all rows or columns from a worksheet or for a specific row and column.
If the row height and column width are not specified, they are automatically sized with the cell content.
// Create an instance of the class that exports Excel files, having two sheets
ExcelDocument workbook = new ExcelDocument(2);
// Get the table of data for the first worksheet
ExcelTable xlsFirstTable =
((ExcelWorksheet)workbook.easy_getSheetAt(0)).easy_getExcelTable();
...
// Set row height for the first row in table
xlsFirstTable.easy_getRowAt(0).setHeight(30);
// Set column widths for the first 5 columns
xlsFirstTable.setColumnWidth(0, 70);
xlsFirstTable.setColumnWidth(1, 100);
xlsFirstTable.setColumnWidth(2, 70);
xlsFirstTable.setColumnWidth(3, 100);
xlsFirstTable.setColumnWidth(4, 70);
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Row height and column width.xlsx");
' Create an instance of the class that exports Excel files, having two sheetsDim workbook As New ExcelDocument(2)
' Get the table of data for the first worksheetDim xlsFirstTab As ExcelWorksheet = workbook.easy_getSheetAt(0)
Dim xlsFirstTable = xlsFirstTab.easy_getExcelTable()
...
' Set row height for the first row in table
xlsFirstTable.easy_getRowAt(0).setHeight(30)
' Set column widths for the first 5 columns
xlsFirstTable.setColumnWidth(0, 70)
xlsFirstTable.setColumnWidth(1, 100)
xlsFirstTable.setColumnWidth(2, 70)
xlsFirstTable.setColumnWidth(3, 100)
xlsFirstTable.setColumnWidth(4, 70)
' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Row height and column width.xlsx")
C++// Create an instance of the class that exports Excel files
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook) ;
// Create two sheets
workbook->easy_addWorksheet_2("First tab");
workbook->easy_addWorksheet_2("Second tab");
// Get the table of data for the first worksheet
EasyXLS::IExcelWorksheetPtr xlsFirstTab =
(EasyXLS::IExcelWorksheetPtr)workbook->easy_getSheetAt(0);
EasyXLS::IExcelTablePtr xlsFirstTable = xlsFirstTab->easy_getExcelTable();
...
// Set row height for the first row in table
xlsFirstTable->easy_getRowAt(0)->setHeight(30);
// Set column widths for the first 5 columns
xlsFirstTable->setColumnWidth_2(0, 70);
xlsFirstTable->setColumnWidth_2(1, 100);
xlsFirstTable->setColumnWidth_2(2, 70);
xlsFirstTable->setColumnWidth_2(3, 100);
xlsFirstTable->setColumnWidth_2(4, 70);
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Row height and column width.xlsx");
Click here to see Continuous Code ListingC++.NET// Create an instance of the class that exports Excel files, having two sheets
ExcelDocument ^workbook = gcnew ExcelDocument(2);
// Get the table of data for the first worksheet
ExcelWorksheet ^xlsFirstTab =
safe_cast<ExcelWorksheet^>(workbook->easy_getSheetAt(0));
ExcelTable ^xlsFirstTable = xlsFirstTab->easy_getExcelTable();
...
// Set row height for the first row in table
xlsFirstTable->easy_getRowAt(0)->setHeight(30);
// Set column widths for the first 5 columns
xlsFirstTable->setColumnWidth(0, 70);
xlsFirstTable->setColumnWidth(1, 100);
xlsFirstTable->setColumnWidth(2, 70);
xlsFirstTable->setColumnWidth(3, 100);
xlsFirstTable->setColumnWidth(4, 70);
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Row height and column width.xlsx");
Click here to see Continuous Code Listing
// Create an instance of the class that exports Excel files, having two sheets
ExcelDocument workbook = new ExcelDocument(2);
// Get the table of data for the first worksheet
ExcelTable xlsFirstTable =
((ExcelWorksheet)workbook.easy_getSheetAt(0)).easy_getExcelTable();
...
// Set row height for the first row in table
xlsFirstTable.easy_getRowAt(0).setHeight(30);
// Set column widths for the first 5 columns
xlsFirstTable.setColumnWidth(0, 70);
xlsFirstTable.setColumnWidth(1, 100);
xlsFirstTable.setColumnWidth(2, 70);
xlsFirstTable.setColumnWidth(3, 100);
xlsFirstTable.setColumnWidth(4, 70);
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Row height and column width.xlsx");
.NET:// Create an instance of the class that exports Excel files
$workbook = new COM("EasyXLS.ExcelDocument");
// Create two sheets
$workbook->easy_addWorksheet_2("First tab");
$workbook->easy_addWorksheet_2("Second tab");
// Get the table of data for the first worksheet
$xlsFirstTable = $workbook->easy_getSheetAt(0)->easy_getExcelTable();
...
// Set row height for the first row in table
$xlsFirstTable->easy_getRowAt(0)->setHeight(30);
// Set column widths for the first 5 columns
$xlsFirstTable->setColumnWidth_2(0, 70);
$xlsFirstTable->setColumnWidth_2(1, 100);
$xlsFirstTable->setColumnWidth_2(2, 70);
$xlsFirstTable->setColumnWidth_2(3, 100);
$xlsFirstTable->setColumnWidth_2(4, 70);
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Row height and column width.xlsx");
Click here to see Continuous Code ListingJava:// Create an instance of the class that exports Excel files
$workbook = new java("EasyXLS.ExcelDocument");
// Create two sheets
$workbook->easy_addWorksheet("First tab");
$workbook->easy_addWorksheet("Second tab");
// Get the table of data for the first worksheet
$xlsFirstTable = $workbook->easy_getSheetAt(0)->easy_getExcelTable();
...
// Set row height for the first row in table
$xlsFirstTable->easy_getRowAt(0)->setHeight(30);
// Set column widths
$xlsFirstTable->setColumnWidth(0, 70);
$xlsFirstTable->setColumnWidth(1, 100);
$xlsFirstTable->setColumnWidth(2, 70);
$xlsFirstTable->setColumnWidth(3, 100);
$xlsFirstTable->setColumnWidth(4, 70);
// Export the Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Row height and column width.xlsx");
Click here to see Continuous Code Listing
' Create an instance of the class that exports Excel filesset workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Create two sheets
workbook.easy_addWorksheet_2("First tab")
workbook.easy_addWorksheet_2("Second tab")
' Get the table of data for the first worksheetSet xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
...
' Set row height for the first row in table
xlsFirstTable.easy_getRowAt(0).setHeight(30)
' Set column widths for the first 5 columns
xlsFirstTable.setColumnWidth_2 0, 70
xlsFirstTable.setColumnWidth_2 1, 100
xlsFirstTable.setColumnWidth_2 2, 70
xlsFirstTable.setColumnWidth_2 3, 100
xlsFirstTable.setColumnWidth_2 4, 70
' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Row height and column width.xlsx")
' Create an instance of the class that exports Excel filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Create two sheets
workbook.easy_addWorksheet_2("First tab")
workbook.easy_addWorksheet_2("Second tab")
' Get the table of data for the first worksheetSet xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
...
' Set row height for the first row in table
xlsFirstTable.easy_getRowAt(0).setHeight(30)
' Set column widths for the first 5 columns
xlsFirstTable.setColumnWidth_2 0, 70
xlsFirstTable.setColumnWidth_2 1, 100
xlsFirstTable.setColumnWidth_2 2, 70
xlsFirstTable.setColumnWidth_2 3, 100
xlsFirstTable.setColumnWidth_2 4, 70
' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Row height and column width.xlsx")
' Create an instance of the class that exports Excel filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Create two sheets
workbook.easy_addWorksheet_2("First tab")
workbook.easy_addWorksheet_2("Second tab")
' Get the table of data for the first worksheetSet xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
...
' Set row height for the first row in table
xlsFirstTable.easy_getRowAt(0).setHeight(30)
' Set column widths for the first 5 columns
xlsFirstTable.setColumnWidth_2 0, 70
xlsFirstTable.setColumnWidth_2 1, 100
xlsFirstTable.setColumnWidth_2 2, 70
xlsFirstTable.setColumnWidth_2 3, 100
xlsFirstTable.setColumnWidth_2 4, 70
' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Row height and column width.xlsx")
<!-- Create an instance of the class that exports Excel files --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Create the worksheets (2) --><cfset ret = workbook.easy_addWorksheet("First tab")><cfset ret = workbook.easy_addWorksheet("Second tab")><!-- Get the table of data for the first worksheet --><cfset xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()>
...
<!-- Set row height for the first row in table --><cfset ret = xlsFirstTable.easy_getRowAt(0).setHeight(30)><!-- Set column widths for the first 5 columns --><cfset xlsFirstTable.setColumnWidth(0, 70)><cfset xlsFirstTable.setColumnWidth(1, 100)><cfset xlsFirstTable.setColumnWidth(2, 70)><cfset xlsFirstTable.setColumnWidth(3, 100)><cfset xlsFirstTable.setColumnWidth(4, 70)><!-- Export Excel file --><cfset ret = workbook.easy_WriteXLSXFile("C:\Samples\Row height and column width.xlsx")>
.NET:# Create an instance of the class that exports Excel files, having two sheets
workbook = ExcelDocument(2)
# Get the table of data for the first worksheet
xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
...
# Set row height for the first row in table
xlsFirstTable.easy_getRowAt(0).setHeight(30)
# Set column widths
xlsFirstTable.setColumnWidth(0, 70)
xlsFirstTable.setColumnWidth(1, 100)
xlsFirstTable.setColumnWidth(2, 70)
xlsFirstTable.setColumnWidth(3, 100)
xlsFirstTable.setColumnWidth(4, 70)
# Export the Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Row height and column width.xlsx")
Click here to see Continuous Code ListingJava:# Create an instance of the class that exports Excel files, having two sheets
workbook = gateway.jvm.ExcelDocument(2)
# Get the table of data for the first worksheet
xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
...
# Set row height for the first row in table
xlsFirstTable.easy_getRowAt(0).setHeight(30)
# Set column widths
xlsFirstTable.setColumnWidth(0, 70)
xlsFirstTable.setColumnWidth(1, 100)
xlsFirstTable.setColumnWidth(2, 70)
xlsFirstTable.setColumnWidth(3, 100)
xlsFirstTable.setColumnWidth(4, 70)
# Export the Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Row height and column width.xlsx")
Click here to see Continuous Code Listing
The screen shot below represents the exported Excel file that has the column widths and one row height specified, Excel file generated by the code sample above.
EasyXLS allows you to set the column width for all the columns in the worksheet using ExcelTable.setColumnWidth method.
Row height for all rows
EasyXLS allows you to set the row height for all the rows in the worksheet using ExcelTable.setRowHeight method.
Auto column width
If the column width is not specified, it is automatically sized with the cell content. If the Excel file was previously imported and the column width is set, the column width can be forced to automatic width by setting the column width to -1 value using ExcelTable.setColumnWidth method.
Auto row height
If the row height is not specified, it is automatically sized with the cell content. If the Excel file was previously imported and the row height is set, the row height can be forced to automatic height by setting the row height to -1 value using ExcelTable.setRowHeight method.