Skip to content

Commit

Permalink
Merge pull request #70 from SyncfusionExamples/ConvertXlsToXlsx
Browse files Browse the repository at this point in the history
C# Example for converting XLS to XLSX format
  • Loading branch information
Mohan2401 authored Jan 16, 2024
2 parents 08014e6 + acb97d7 commit 3f9fba5
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Real Time Examples in Excel/ConvertXlsToXlsx/ConvertXlsToXlsx.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34310.174
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConvertXlsToXlsx", "ConvertXlsToXlsx\ConvertXlsToXlsx.csproj", "{291D0D7F-683B-47A2-9AFF-0BBD1E8548ED}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{291D0D7F-683B-47A2-9AFF-0BBD1E8548ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{291D0D7F-683B-47A2-9AFF-0BBD1E8548ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
{291D0D7F-683B-47A2-9AFF-0BBD1E8548ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
{291D0D7F-683B-47A2-9AFF-0BBD1E8548ED}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5C3D7A03-6AD8-4FD0-8FC8-A24EE0450E13}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="24.1.45" />
</ItemGroup>

</Project>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Syncfusion.XlsIO;


namespace ConvertXlsToXlsx
{
class Program
{
private static string inputPath = @"../../../Data/";

private static string outputPath = @"../../../Output/";
static void Main(string[] args)
{
string fileName = "Report.xls";

//Split the Excel document
ConvertXlsToXLSX(inputPath + fileName);
}
/// <summary>
/// Convert the Excel document from the given path
/// </summary>
/// <param name="filePath">Excel file path</param>
private static void ConvertXlsToXLSX(string filePath)
{
FileStream inputData = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite);

using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Open(inputData);
IWorksheets worksheets = workbook.Worksheets;

workbook.Version = ExcelVersion.Xlsx;

FileStream fileStream = new FileStream(outputPath + Path.GetFileNameWithoutExtension(filePath) + ".xlsx", FileMode.Create, FileAccess.ReadWrite);
workbook.SaveAs(fileStream);
fileStream.Close();
}
}
}
}

0 comments on commit 3f9fba5

Please sign in to comment.