-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from SyncfusionExamples/ConvertXlsToXlsx
C# Example for converting XLS to XLSX format
- Loading branch information
Showing
5 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
Real Time Examples in Excel/ConvertXlsToXlsx/ConvertXlsToXlsx.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
14 changes: 14 additions & 0 deletions
14
Real Time Examples in Excel/ConvertXlsToXlsx/ConvertXlsToXlsx/ConvertXlsToXlsx.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+43 KB
Real Time Examples in Excel/ConvertXlsToXlsx/ConvertXlsToXlsx/Data/Report.xls
Binary file not shown.
Binary file added
BIN
+12.7 KB
Real Time Examples in Excel/ConvertXlsToXlsx/ConvertXlsToXlsx/Output/Report.xlsx
Binary file not shown.
42 changes: 42 additions & 0 deletions
42
Real Time Examples in Excel/ConvertXlsToXlsx/ConvertXlsToXlsx/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
} | ||
|