Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Document-Processing-toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -6088,6 +6088,9 @@
<li>
<a href="/document-processing/excel/excel-library/net/faqs/how-to-set-the-first-item-in-a-list-as-the-default-selected-value-in-an-Excel-file">How to set the first item in a list as the default value in an Excel?</a>
</li>
<li>
<a href="/document-processing/excel/excel-library/net/faqs/how-to-perform-a-clean-installation-of-a-NuGet-package-from-a-local-source">How to perform a clean installation of a NuGet package from a local source?</a>
</li>
</ul>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,38 @@ The following code snippet shows how to convert an Excel chart to an image using
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/Chart%20to%20Image/Chart%20to%20Image/.NET/Chart%20to%20Image/Chart%20to%20Image/Program.cs,180" %}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
//Initialize application
IApplication application = excelEngine.Excel;

//Set the default version as Xlsx
application.DefaultVersion = ExcelVersion.Xlsx;

// Initialize XlsIORenderer
application.XlsIORenderer = new XlsIORenderer();
//Initialize XlsIORenderer
application.XlsIORenderer = new XlsIORenderer();

//Set converter chart image format to PNG
application.XlsIORenderer.ChartRenderingOptions.ImageFormat = ExportImageFormat.Png;
//Set converter chart image format to PNG or JPEG
application.XlsIORenderer.ChartRenderingOptions.ImageFormat = ExportImageFormat.Png;

FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream);
IWorksheet worksheet = workbook.Worksheets[0];
//Set the chart image quality to best
application.XlsIORenderer.ChartRenderingOptions.ScalingMode = ScalingMode.Best;

IChart chart = worksheet.Charts[0];
//Open existing workbook with chart
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream);
IWorksheet worksheet = workbook.Worksheets[0];

//Access the chart from the worksheet
IChart chart = worksheet.Charts[0];

#region Save
//Saving the workbook
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Image.png"), FileMode.Create, FileAccess.Write);
chart.SaveAsImage(outputStream);
#endregion
#region Save
//Exporting the chart as image
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Image.png"), FileMode.Create, FileAccess.Write);
chart.SaveAsImage(outputStream);
#endregion

//Dispose streams
outputStream.Dispose();
inputStream.Dispose();
//Dispose streams
outputStream.Dispose();
inputStream.Dispose();
}
{% endhighlight %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,52 @@ workbook.DetectDateTimeInValue = False
{% endhighlight %}
{% endtabs %}

N> To display the **$** symbol, apply a currency or accounting number format. Using a number format without any currency symbol does not show any currency symbol in the value.

{% tabs %}
{% highlight c# tabtitle="C# [Cross-platform]" %}
//Plain number format
sheet.Range["A1"].Number = 100;
sheet.Range["A1"].NumberFormat = "0.00"; //shows 100.00

//Currency format
sheet.Range["A2"].Number = 1234.56;
sheet.Range["A2"].NumberFormat = "$#,##0.00"; //shows $1,234.56

//Accounting format
sheet.Range["A3"].Number = 234;
sheet.Range["A3"].NumberFormat = "_($* #,##0.00_)"; //shows $ 234.00
{% endhighlight %}

{% highlight c# tabtitle="C# [Windows-specific]" %}
//Plain number format
sheet.Range["A1"].Number = 100;
sheet.Range["A1"].NumberFormat = "0.00"; //shows 100.00

//Currency format
sheet.Range["A2"].Number = 1234.56;
sheet.Range["A2"].NumberFormat = "$#,##0.00"; //shows $1,234.56

//Accounting format
sheet.Range["A3"].Number = 234;
sheet.Range["A3"].NumberFormat = "_($* #,##0.00_)"; //shows $ 234.00
{% endhighlight %}

{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
'Plain Number format
sheet.Range("A1").Number = 100
sheet.Range("A1").NumberFormat = "0.00" 'shows 100.00

'Currency format
sheet.Range("A2").Number = 1234.56
sheet.Range("A2").NumberFormat = "$#,##0.00" 'shows $1,234.56

'Accounting format
sheet.Range("A3").Number = 234
sheet.Range("A3").NumberFormat = "_($* #,##0.00_)" 'shows $ 234.00
{% endhighlight %}
{% endtabs %}

## Number Format Detection Behavior Based on System Culture

In Microsoft Excel, when a value is inserted, the system's culture settings determine whether the value is interpreted as a [Text](https://help.syncfusion.com/cr/document-processing/Syncfusion.XlsIO.IRange.html#Syncfusion_XlsIO_IRange_Text) or [Number](https://help.syncfusion.com/cr/document-processing/Syncfusion.XlsIO.IRange.html#Syncfusion_XlsIO_IRange_Number). If it is a valid number according to the current culture, Excel automatically detects and applies a corresponding number format.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,35 @@ A complete working example for list data validation in C# is present on [this Gi

N> The [ListOfValues](https://help.syncfusion.com/cr/document-processing/Syncfusion.XlsIO.IDataValidation.html#Syncfusion_XlsIO_IDataValidation_ListOfValues) property should be used when the values in the Data Validation list are entered manually whose limit is only 255 characters including separators.

### List Validation with User-defined Range

The following code snippet illustrates how to set list validation for a user-defined range.

{% tabs %}
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/Data%20Validation/UserDefinedValidation/.NET/UserDefinedValidation/UserDefinedValidation/Program.cs,180" %}
//Data validation for the user-defined range
IDataValidation validation = worksheet.Range["C3"].DataValidation;
validation.AllowType = ExcelDataType.User;
validation.FirstFormula = "=Sheet1!$B$1:$B$3";
{% endhighlight %}

{% highlight c# tabtitle="C# [Windows-specific]" %}
//Data validation for the user-defined range
IDataValidation validation = worksheet.Range["C3"].DataValidation;
validation.AllowType = ExcelDataType.User;
validation.FirstFormula = "=Sheet1!$B$1:$B$3";
{% endhighlight %}

{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
'Data validation for the user-defined range
Dim validation As IDataValidation = worksheet.Range("C3").DataValidation
validation.AllowType = ExcelDataType.User
validation.FirstFormula = "=Sheet1!$B$1:$B$3"
{% endhighlight %}
{% endtabs %}

A complete working example of list validation for a user-defined range in C# is present on <a href="https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/Data%20Validation/UserDefinedValidation/.NET/UserDefinedValidation">this GitHub page</a>.

## Number Validation

The following code snippet illustrates how to set number validation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1024,4 +1024,118 @@ End Using
{% endhighlight %}
{% endtabs %}

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

## Paper Size

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.

The following code snippet shows how to use PaperSize.

{% tabs %}
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/Worksheet%20Features/PaperSize/.NET/PaperSize/PaperSize/Program.cs,180" %}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
IWorksheet worksheet = workbook.Worksheets[0];

//Set the paper size to A4
worksheet.PageSetup.PaperSize = ExcelPaperSize.PaperA4;

//Saving the workbook
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
}
{% endhighlight %}

{% highlight c# tabtitle="C# [Windows-specific]" %}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];

//Set the paper size to A4
worksheet.PageSetup.PaperSize = ExcelPaperSize.PaperA4;

//Saving the workbook
workbook.SaveAs("Output.xlsx");
}
{% endhighlight %}

{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
Using excelEngine As ExcelEngine = New ExcelEngine()
Dim application As IApplication = excelEngine.Excel
application.DefaultVersion = ExcelVersion.Xlsx
Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.xlsx")
Dim worksheet As IWorksheet = workbook.Worksheets(0)

'Set the paper size to A4
worksheet.PageSetup.PaperSize = ExcelPaperSize.PaperA4

'Saving the workbook
workbook.SaveAs("Output.xlsx")
End Using
{% endhighlight %}
{% endtabs %}

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>.

## Orientation

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.

The following code snippet shows how to use Orientation.

{% tabs %}
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/Worksheet%20Features/Orientation/.NET/Orientation/Orientation/Program.cs,180" %}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
IWorksheet worksheet = workbook.Worksheets[0];

//Set the page orientation
worksheet.PageSetup.Orientation = ExcelPageOrientation.Landscape;

//Saving the workbook
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
}
{% endhighlight %}

{% highlight c# tabtitle="C# [Windows-specific]" %}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];

//Set the page orientation
worksheet.PageSetup.Orientation = ExcelPageOrientation.Landscape;

//Saving the workbook
workbook.SaveAs("Output.xlsx");
}
{% endhighlight %}

{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
Using excelEngine As ExcelEngine = New ExcelEngine()
Dim application As IApplication = excelEngine.Excel
application.DefaultVersion = ExcelVersion.Xlsx
Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.xlsx")
Dim worksheet As IWorksheet = workbook.Worksheets(0)

'Set the page orientation
worksheet.PageSetup.Orientation = ExcelPageOrientation.Landscape

'Saving the workbook
workbook.SaveAs("Output.xlsx")
End Using
{% endhighlight %}
{% endtabs %}

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>.
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,9 @@ using (ExcelEngine excelEngine = new ExcelEngine())
worksheet.Range["A9:A14"].RowHeight = 15;
worksheet.Range["A15:A23"].RowHeight = 18;

//Saving the Excel to the MemoryStream
MemoryStream stream = new MemoryStream();
MemoryStream stream = new MemoryStream();
workbook.SaveAs(stream);

//Set the position as '0'.
stream.Position = 0;

//Download the Excel file in the browser
FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel");
fileStreamResult.FileDownloadName = "Output.xlsx";
return fileStreamResult;
return Convert.ToBase64String(stream.ToArray());
}

{% endhighlight %}
Expand Down
Loading