Skip to content

Commit 1eb2109

Browse files
ES-975464 - Committed the changes
1 parent a598903 commit 1eb2109

File tree

1 file changed

+76
-7
lines changed

1 file changed

+76
-7
lines changed

README.md

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# How to Change the Row Height for the Exported Excel Sheet
1+
# How to Change the Row Height for the Exported Excel Sheet in WinForms DataGrid?
22

3-
# About the example
3+
This example illustrates how to change the row height of the excel sheet exported from the [WinForms DataGrid](https://www.syncfusion.com/winforms-ui-controls/datagrid) (SfDataGrid) and also shows how to auto adjust the row height of the exported excel sheet based on its content.
44

5-
This example illustrates how to change the row height of the excel sheet exported from the [WinForms DataGrid](https://www.syncfusion.com/winforms-ui-controls/datagrid) and also shows how to auto adjust the row height of the exported excel sheet based on its content.
5+
You can change the row height of the exported excel sheet using **Worksheets.UsedRange.RowHeight** property.
66

7-
You can change the row height of the exported excel sheet using `Worksheets.UsedRange.RowHeight` property.
7+
### C#
88

9-
```C#
9+
```csharp
1010
private void ExportToExcel_Click(object sender, System.EventArgs e)
1111
{
1212
ExcelExportingOptions options = new ExcelExportingOptions();
@@ -44,10 +44,45 @@ private void ExportToExcel_Click(object sender, System.EventArgs e)
4444
}
4545
```
4646

47-
You can use `AutofitRows` method to adjust the row height of the exported excel sheet based on the content.
47+
### VB
4848

49+
``` vb
50+
Private Sub ExportToExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button2.Click
51+
Dim options As New ExcelExportingOptions()
52+
Dim excelEngine = sfDataGrid.ExportToExcel(sfDataGrid.View, options)
53+
Dim workBook = excelEngine.Excel.Workbooks(0)
54+
55+
'Set row height.
56+
workBook.Worksheets(0).UsedRange.RowHeight = 30
57+
58+
Dim sfd As SaveFileDialog = New SaveFileDialog With {.FilterIndex = 2, .Filter = "Excel 97 to 2003 Files(*.xls)|*.xls|Excel 2007 to 2010 Files(*.xlsx)|*.xlsx", .FileName = "Book1"}
59+
60+
If sfd.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
61+
Using stream As Stream = sfd.OpenFile()
62+
If sfd.FilterIndex = 1 Then
63+
workBook.Version = ExcelVersion.Excel97to2003
64+
Else
65+
workBook.Version = ExcelVersion.Excel2010
66+
End If
67+
workBook.SaveAs(stream)
68+
End Using
69+
70+
'Message box confirmation to view the created spreadsheet.
71+
If MessageBox.Show("Do you want to view the workbook?", "Workbook has been created", MessageBoxButtons.OKCancel) = System.Windows.Forms.DialogResult.OK Then
72+
'Launching the Excel file using the default Application.[MS Excel Or Free ExcelViewer]
73+
System.Diagnostics.Process.Start(sfd.FileName)
74+
End If
75+
End If
76+
End Sub
77+
```
4978

50-
```C#
79+
![How to Change the Row Height for the Exported Excel Sheet in WinForms DataGrid](https://www.syncfusion.com/uploads/user/kb/wf/wf-46156/wf-46156_img1.png)
80+
81+
You can use **AutofitRows** method to adjust the row height of the exported excel sheet based on the content.
82+
83+
### C#
84+
85+
``` csharp
5186
private void ExportToExcel_Click(object sender, System.EventArgs e)
5287
{
5388
ExcelExportingOptions options = new ExcelExportingOptions();
@@ -84,3 +119,37 @@ private void ExportToExcel_Click(object sender, System.EventArgs e)
84119
}
85120
}
86121
```
122+
123+
### VB
124+
125+
``` vb
126+
Private Sub ExportToExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button2.Click
127+
Dim options As New ExcelExportingOptions()
128+
Dim excelEngine = sfDataGrid.ExportToExcel(sfDataGrid.View, options)
129+
Dim workBook = excelEngine.Excel.Workbooks(0)
130+
131+
'Row height will be set based on the content.
132+
workBook.Worksheets(0).UsedRange.AutofitRows()
133+
134+
Dim sfd As SaveFileDialog = New SaveFileDialog With {.FilterIndex = 2, .Filter = "Excel 97 to 2003 Files(*.xls)|*.xls|Excel 2007 to 2010 Files(*.xlsx)|*.xlsx", .FileName = "Book1"}
135+
136+
If sfd.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
137+
Using stream As Stream = sfd.OpenFile()
138+
If sfd.FilterIndex = 1 Then
139+
workBook.Version = ExcelVersion.Excel97to2003
140+
Else
141+
workBook.Version = ExcelVersion.Excel2010
142+
End If
143+
workBook.SaveAs(stream)
144+
End Using
145+
146+
'Message box confirmation to view the created spreadsheet.
147+
If MessageBox.Show("Do you want to view the workbook?", "Workbook has been created", MessageBoxButtons.OKCancel) = System.Windows.Forms.DialogResult.OK Then
148+
'Launching the Excel file using the default Application.[MS Excel Or Free ExcelViewer]
149+
System.Diagnostics.Process.Start(sfd.FileName)
150+
End If
151+
End If
152+
End Sub
153+
```
154+
155+
![How to Change the Row Height for the Exported Excel Sheet in WinForms DataGrid](https://www.syncfusion.com/uploads/user/kb/wf/wf-46156/wf-46156_img2.png)

0 commit comments

Comments
 (0)