Skip to content

Commit db2936e

Browse files
authored
Merge pull request #1768 from syncfusion-content/988184-PageSetup
988184 - Specify the paper size and orientation in Excel to PDF conversion
2 parents 7d43478 + ff59f23 commit db2936e

File tree

1 file changed

+115
-1
lines changed

1 file changed

+115
-1
lines changed

Document-Processing/Excel/Excel-Library/NET/Worksheet/Page-Setup-Options.md

Lines changed: 115 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,4 +1024,118 @@ End Using
10241024
{% endhighlight %}
10251025
{% endtabs %}
10261026

1027-
A complete working example to add headers and footers in an Excel document using C# is present on [this GitHub page.](https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/Worksheet%20Features/Header%20and%20Footer/.NET/Header%20and%20Footer)
1027+
A complete working example to add headers and footers in an Excel document using C# is present on [this GitHub page.](https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/Worksheet%20Features/Header%20and%20Footer/.NET/Header%20and%20Footer)
1028+
1029+
## Paper Size
1030+
1031+
The <a href="https://help.syncfusion.com/cr/document-processing/Syncfusion.XlsIO.Interfaces.IPageSetupBase.html#Syncfusion_XlsIO_Interfaces_IPageSetupBase_PaperSize">PaperSize</a> functionality allows you to specify the paper size for worksheet.
1032+
1033+
The following code snippet shows how to use PaperSize.
1034+
1035+
{% tabs %}
1036+
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/Worksheet%20Features/PaperSize/.NET/PaperSize/PaperSize/Program.cs,180" %}
1037+
using (ExcelEngine excelEngine = new ExcelEngine())
1038+
{
1039+
IApplication application = excelEngine.Excel;
1040+
application.DefaultVersion = ExcelVersion.Xlsx;
1041+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1042+
IWorksheet worksheet = workbook.Worksheets[0];
1043+
1044+
//Set the paper size to A4
1045+
worksheet.PageSetup.PaperSize = ExcelPaperSize.PaperA4;
1046+
1047+
//Saving the workbook
1048+
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
1049+
}
1050+
{% endhighlight %}
1051+
1052+
{% highlight c# tabtitle="C# [Windows-specific]" %}
1053+
using (ExcelEngine excelEngine = new ExcelEngine())
1054+
{
1055+
IApplication application = excelEngine.Excel;
1056+
application.DefaultVersion = ExcelVersion.Xlsx;
1057+
IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx");
1058+
IWorksheet worksheet = workbook.Worksheets[0];
1059+
1060+
//Set the paper size to A4
1061+
worksheet.PageSetup.PaperSize = ExcelPaperSize.PaperA4;
1062+
1063+
//Saving the workbook
1064+
workbook.SaveAs("Output.xlsx");
1065+
}
1066+
{% endhighlight %}
1067+
1068+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
1069+
Using excelEngine As ExcelEngine = New ExcelEngine()
1070+
Dim application As IApplication = excelEngine.Excel
1071+
application.DefaultVersion = ExcelVersion.Xlsx
1072+
Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.xlsx")
1073+
Dim worksheet As IWorksheet = workbook.Worksheets(0)
1074+
1075+
'Set the paper size to A4
1076+
worksheet.PageSetup.PaperSize = ExcelPaperSize.PaperA4
1077+
1078+
'Saving the workbook
1079+
workbook.SaveAs("Output.xlsx")
1080+
End Using
1081+
{% endhighlight %}
1082+
{% endtabs %}
1083+
1084+
A complete working example to set the paper size in C# is present on <a href="https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/Worksheet%20Features/PaperSize/.NET/PaperSize">this GitHub page</a>.
1085+
1086+
## Orientation
1087+
1088+
The <a href="https://help.syncfusion.com/cr/document-processing/Syncfusion.XlsIO.Interfaces.IPageSetupBase.html#Syncfusion_XlsIO_Interfaces_IPageSetupBase_Orientation">Orientation</a> functionality allows you to specify the orientation for worksheet.
1089+
1090+
The following code snippet shows how to use Orientation.
1091+
1092+
{% tabs %}
1093+
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/Worksheet%20Features/Orientation/.NET/Orientation/Orientation/Program.cs,180" %}
1094+
using (ExcelEngine excelEngine = new ExcelEngine())
1095+
{
1096+
IApplication application = excelEngine.Excel;
1097+
application.DefaultVersion = ExcelVersion.Xlsx;
1098+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1099+
IWorksheet worksheet = workbook.Worksheets[0];
1100+
1101+
//Set the page orientation
1102+
worksheet.PageSetup.Orientation = ExcelPageOrientation.Landscape;
1103+
1104+
//Saving the workbook
1105+
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
1106+
}
1107+
{% endhighlight %}
1108+
1109+
{% highlight c# tabtitle="C# [Windows-specific]" %}
1110+
using (ExcelEngine excelEngine = new ExcelEngine())
1111+
{
1112+
IApplication application = excelEngine.Excel;
1113+
application.DefaultVersion = ExcelVersion.Xlsx;
1114+
IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx");
1115+
IWorksheet worksheet = workbook.Worksheets[0];
1116+
1117+
//Set the page orientation
1118+
worksheet.PageSetup.Orientation = ExcelPageOrientation.Landscape;
1119+
1120+
//Saving the workbook
1121+
workbook.SaveAs("Output.xlsx");
1122+
}
1123+
{% endhighlight %}
1124+
1125+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
1126+
Using excelEngine As ExcelEngine = New ExcelEngine()
1127+
Dim application As IApplication = excelEngine.Excel
1128+
application.DefaultVersion = ExcelVersion.Xlsx
1129+
Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.xlsx")
1130+
Dim worksheet As IWorksheet = workbook.Worksheets(0)
1131+
1132+
'Set the page orientation
1133+
worksheet.PageSetup.Orientation = ExcelPageOrientation.Landscape
1134+
1135+
'Saving the workbook
1136+
workbook.SaveAs("Output.xlsx")
1137+
End Using
1138+
{% endhighlight %}
1139+
{% endtabs %}
1140+
1141+
A complete working example to set the page orientation in C# is present on <a href="https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/Worksheet%20Features/Orientation/.NET/Orientation">this GitHub page</a>.

0 commit comments

Comments
 (0)