Skip to content

Commit

Permalink
Rangevalues to TwoDimensionalArray
Browse files Browse the repository at this point in the history
  • Loading branch information
Kurmitha4004 committed Feb 15, 2024
1 parent df42f7b commit 786cb22
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
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 not shown.
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;
}
}
}
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>

0 comments on commit 786cb22

Please sign in to comment.