-
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.
- Loading branch information
1 parent
df42f7b
commit 786cb22
Showing
4 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...lArray/NET Standard/Ranges-into-TwoDimensionalArrray/Ranges-into-TwoDimensionalArrray.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}") = "Ranges-into-TwoDimensionalArrray", "Ranges-into-TwoDimensionalArrray\Ranges-into-TwoDimensionalArrray.csproj", "{A948FC11-55E5-49F2-9F96-68DADA090B73}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{A948FC11-55E5-49F2-9F96-68DADA090B73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A948FC11-55E5-49F2-9F96-68DADA090B73}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A948FC11-55E5-49F2-9F96-68DADA090B73}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A948FC11-55E5-49F2-9F96-68DADA090B73}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {B748AF50-0513-4CB9-BC50-915139188373} | ||
EndGlobalSection | ||
EndGlobal |
Binary file added
BIN
+14.8 KB
...Ranges-into-TwoDimensionalArrray/Ranges-into-TwoDimensionalArrray/Data/InputTemplate.xlsx
Binary file not shown.
53 changes: 53 additions & 0 deletions
53
...NET Standard/Ranges-into-TwoDimensionalArrray/Ranges-into-TwoDimensionalArrray/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,53 @@ | ||
using Syncfusion.XlsIO; | ||
|
||
namespace Ranges_into_TwoDimensionalArray | ||
{ | ||
class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
//Create an instance of ExcelEngine | ||
using (ExcelEngine excelEngine = new ExcelEngine()) | ||
{ | ||
//Instantiate the Excel application object | ||
IApplication application = excelEngine.Excel; | ||
|
||
//Set the default application version as Excel 2016 | ||
application.DefaultVersion = ExcelVersion.Xlsx; | ||
|
||
//Loads an existing workbook | ||
FileStream fileStream = new FileStream(@"../../../Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read); | ||
IWorkbook workbook = application.Workbooks.Open(fileStream); | ||
IWorksheet worksheet = workbook.Worksheets[0]; | ||
|
||
//Set the range to convert into two dimensional array | ||
IRange range = worksheet["B1:E5"]; | ||
string[,] arrayOfArrays = ConvertIRangeToArray(worksheet, range); | ||
} | ||
} | ||
/// <summary> | ||
/// Converting range values into 2 dimensional array | ||
/// </summary> | ||
public static string[,] ConvertIRangeToArray(IWorksheet worksheet, IRange range) | ||
{ | ||
int startRow = range.Row; | ||
int startCol = range.Column; | ||
int endRow = range.LastRow; | ||
int endCol = range.LastColumn; | ||
|
||
string[,] numbers = new string[endRow - startRow + 1, endCol - startCol + 1]; | ||
|
||
for (int i = 0; i <= endRow - startRow; i++) | ||
{ | ||
for (int j = 0; j <= endCol - startCol; j++) | ||
{ | ||
numbers[i, j] = worksheet[startRow + i, startCol + j].Value; | ||
Console.Write(numbers[i, j]); | ||
Console.Write("\t"); | ||
} | ||
Console.Write("\n______________________________________________\n"); | ||
} | ||
return numbers; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...imensionalArrray/Ranges-into-TwoDimensionalArrray/Ranges-into-TwoDimensionalArrray.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,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<RootNamespace>Ranges_into_TwoDimensionalArrray</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="24.2.6" /> | ||
</ItemGroup> | ||
|
||
</Project> |