We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to convert a CSV file into Excel document using XlsIO in PowerShell?

Platform: WinForms |
Control: XlsIO
Tags: xlsio, csv, powershell

Excel files can be created from PowerShell commands using XlsIO. The following code sample illustrates how to convert a CSV file into Excel document using XlsIO and Powershell.

Powershell commands to convert CSV to Excel file

#Getting Current Directory

$CurrentPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition


#Defining input CSV file

$inputCSV = "$CurrentPath\Data\input.csv"


#Defining output XLSX file

$outputExcel = "$CurrentPath\Output\output.xlsx"


#Defining XlsIO and Compression Assemblies

$XlsIODLLPath = "$CurrentPath\Assemblies\Syncfusion.XlsIO.Base.dll"

$CompressionDLLPath = "$CurrentPath\Assemblies\Syncfusion.Compression.Base.dll"


#Load Assemblies

[Reflection.Assembly]::LoadFrom($XlsIODLLPath) | Out-Null

[Reflection.Assembly]::LoadFrom($CompressionDLLPath) | Out-Null


#Initialize the Excel engine Object

$Engine = New-object -TypeName Syncfusion.XlsIO.ExcelEngine


#Initialize the Excel application object.

$Application = $Engine.Excel


#Define separator

$Separator = ","


#Preserve data type from CSV file

$Application.PreserveCSVDataTypes = '1'


#Open CSV file using XlsIO

$Workbook = $Application.Workbooks.Open([string]$inputCSV ,[string]$Separator)


#Assigning Excel Version

$Workbook.Version = [Syncfusion.XlsIO.ExcelVersion]::Excel2016


#Saving the file as XLSX



Write-Host "CSV File $inputCSV saved as Excel file $outputExcel using XlsIO."


Save the Powershell script file and run the file using below command in Windows Powershell.



If the script throws an exception “PowerShell script is not loaded in the system”, please use below command to run the script. 



powershell.exe -ExecutionPolicy ByPass -FileF:Sample\Sample.ps1 



The sample files can be downloaded here.

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile