<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>excel c# Archives | Selenium Webdriver Appium Complete Tutorial</title>
	<atom:link href="https://automationtesting.in/category/excel-c/feed/" rel="self" type="application/rss+xml" />
	<link>https://automationtesting.in/category/excel-c/</link>
	<description>Automation Testing</description>
	<lastBuildDate>Thu, 26 Sep 2019 10:03:20 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.2.2</generator>
	<item>
		<title>Write Data in Excel Using Column Number in C#</title>
		<link>https://automationtesting.in/write-data-in-excel-using-column-number-in-c/</link>
					<comments>https://automationtesting.in/write-data-in-excel-using-column-number-in-c/#respond</comments>
		
		<dc:creator><![CDATA[]]></dc:creator>
		<pubDate>Thu, 26 Sep 2019 10:03:20 +0000</pubDate>
				<category><![CDATA[excel c#]]></category>
		<category><![CDATA[data driven testing using excel c#]]></category>
		<category><![CDATA[excel operations in c#]]></category>
		<category><![CDATA[how to interact with excel]]></category>
		<category><![CDATA[set data in excel]]></category>
		<category><![CDATA[set data in excel using column number]]></category>
		<category><![CDATA[using column number to write data]]></category>
		<guid isPermaLink="false">http://automationtesting.in/?p=2097</guid>

					<description><![CDATA[<p>Write data in excel using column number in C#, We will discuss about how to write data in excel using column number in C#. Usually we will use the excel sheet to maintain the test data. We might get doubt that why we need to put the test data/results in excel. If an application feed [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://automationtesting.in/write-data-in-excel-using-column-number-in-c/">Write Data in Excel Using Column Number in C#</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img src='http://automationtesting.in/wp-content/uploads/2019/09/WRITE-DATA-TO-EXCEL-USING-COLUMN-NUMBER-Using-C.png'></p><p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script><br />
Write data in excel using column number in C#, We will discuss about how to write data in excel using column number in C#. Usually we will use the excel sheet to maintain the test data. We might get doubt that why we need to put the test data/results in excel. If an application feed so much of data to be need to test; then we will manage those data using external sources like text file, xml file and excel file etc…. Among these; Excel is very user friendly that we can organize the data very easily and we can read and write the data how we want. So, we mostly use excel to maintain the test data and results.</p>
<div class="post-video"><iframe loading="lazy" title="5. How to Write Data To Excel using Column Number in Selenium Webdriver C# | Excel Write in C#" width="1165" height="655" src="https://www.youtube.com/embed/FKcuPiLxIik?wmode=transparent&#038;fs=1"  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
<p>So, if you want to write huge number of test data in excel sheet to feed to the application then we need to know how many rows and columns are there in the excel. If you know exact information about the test data then only we can get the information from the excel in proper way. In this blog we will use to write data in excel using column number in C#. To do this, we need to create a console application in Visual studio and Install Microsoft.Office.Interop.Excel Nuget package.</p>
<p>For this we need to have the below pre-requisites:</p>
<ol>
<li style="font-weight: 400;"><span style="font-weight: 400;">Create a Console Application in Visual Studio</span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">Install </span><b>Microsoft.Office.Interop.Excel</b><span style="font-weight: 400;"> Nuget Package by following below steps</span>
<ul>
<li style="font-weight: 400;"><span style="font-weight: 400;">Under your Console Application, Right Click on reference, Click on Manage Nuget Package </span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">Go to Browse</span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">Under Browse search for “Microsoft.Office.Interop.Excel” </span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">click on “Microsoft.Office.Interop.Excel” and then Click Install</span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">Make sure that your package got installed and appears under References folder under your Console App.</span></li>
</ul>
</li>
</ol>
<p><b>What is Microsoft.Office.Interop.Excel Nuget package?</b></p>
<p>By using this Nuget package we can interact with the excel like reading data from the Excel or writing data to the excel.</p>
<p>To Interact with our Nuget, we need to add the below using statement:</p>
<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<p><b>Using xl = Microsoft.Office.Interop.Excel;</b></p>
<p><b>Below are the classes will use to write the column number:</b></p>
<ol>
<li style="font-weight: 400;"><span style="font-weight: 400;">ExcelApiTest</span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">CheckExcel</span></li>
</ol>
<p><b>Below are the Interfaces will use to Set the cell data using Microsoft.Interop.Excel package:</b></p>
<ol>
<li style="font-weight: 400;"><span style="font-weight: 400;">Xl.Application</span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">Xl.Workbooks</span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">Xl.Workbook</span></li>
</ol>
<p><b>Below collection is needed to create a Hash table:</b></p>
<ol>
<li><span style="font-weight: 400;">Using System.Collections</span></li>
</ol>
<p><b>Below Constructors are called to Interact with the User defined Excel sheet:</b></p>
<ol>
<li style="font-weight: 400;"><span style="font-weight: 400;">ExcelApiTest</span></li>
</ol>
<p><b>Below are the Methods will use to set the cell data using column number:</b></p>
<ol>
<li style="font-weight: 400;"><span style="font-weight: 400;">OpenExcel() //Establish the connection</span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">CloseExcel()//Closes all the connections</span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">SetCellData()</span></li>
</ol>
<p>Following is the code, we have used some Interfaces and methods to create connections, setting the cell data using column number and closing the connections.</p>
<pre class="brush: csharp; title: ; notranslate">
using System;
using System.Collections;
using System.Runtime.InteropServices;
using xl = Microsoft.Office.Interop.Excel;

namespace CSharpPractice
{
    class ExcelApiTest
    {
        xl.Application xlApp = null;
        xl.Workbooks workbooks = null;
        xl.Workbook workbook = null;
        Hashtable sheets;
        public string xlFilePath;

        public ExcelApiTest(string xlFilePath)
        {
            this.xlFilePath = xlFilePath;
        }

        public void OpenExcel()
        {
            xlApp = new xl.Application();
            workbooks = xlApp.Workbooks;
            workbook = workbooks.Open(xlFilePath);
            sheets = new Hashtable();
            int count = 1;
            // Storing worksheet names in Hashtable.
            foreach (xl.Worksheet sheet in workbook.Sheets)
            {
                sheets&#x5B;count] = sheet.Name;
                count++;
            }
        }

        public void CloseExcel()
        {
            workbook.Close(false, xlFilePath, null); // Close the connection to workbook
            Marshal.FinalReleaseComObject(workbook); // Release unmanaged object references.
            workbook = null;

            workbooks.Close();
            Marshal.FinalReleaseComObject(workbooks);
            workbooks = null;

            xlApp.Quit();
            Marshal.FinalReleaseComObject(xlApp);
            xlApp = null;
        }

        public bool SetCellData(string sheetName, int colNumber, int rowNumber, string value)
        {
            OpenExcel();

            int sheetValue = 0;

            try
            {
                if (sheets.ContainsValue(sheetName))
                {
                    foreach (DictionaryEntry sheet in sheets)
                    {
                        if (sheet.Value.Equals(sheetName))
                        {
                            sheetValue = (int)sheet.Key;
                        }
                    }

                    xl.Worksheet worksheet = null;
                    worksheet = workbook.Worksheets&#x5B;sheetValue] as xl.Worksheet;
                    xl.Range range = worksheet.UsedRange;

                    range.Cells&#x5B;rowNumber, colNumber] = value;

                    workbook.Save();

                    Marshal.FinalReleaseComObject(worksheet);
                    worksheet = null;
                    CloseExcel();
                }
            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }
}
</pre>
<p>Below is a sample program which will call the methods from the above program to set the cell data using column number from any excel sheet.</p>
<pre class="brush: csharp; title: ; notranslate">
using System;

namespace CSharpPractice
{
    class CheckExcel
    {
        static void Main(string&#x5B;] args)
        {
            string xlFilePath = &amp;quot;D:/ExcelFiles/TestData.xlsx&amp;quot;;

            ExcelApiTest eat = new ExcelApiTest(xlFilePath);

            eat.SetCellData(&amp;quot;Credentials&amp;quot;, 5, 5,&amp;quot;FAIL&amp;quot;);

        }

    }
}
</pre>
<p><a href="https://youtu.be/FKcuPiLxIik">Please watch the Youtube video for better understanding.</a></p>
<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<div id="themify_builder_content-2097" data-postid="2097" class="themify_builder_content themify_builder_content-2097 themify_builder themify_builder_front">

	</div>
<!-- /themify_builder_content --><p>The post <a rel="nofollow" href="https://automationtesting.in/write-data-in-excel-using-column-number-in-c/">Write Data in Excel Using Column Number in C#</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://automationtesting.in/write-data-in-excel-using-column-number-in-c/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Write Data in Excel Using Column Name in C#</title>
		<link>https://automationtesting.in/write-data-excel-using-column-name-c/</link>
					<comments>https://automationtesting.in/write-data-excel-using-column-name-c/#respond</comments>
		
		<dc:creator><![CDATA[]]></dc:creator>
		<pubDate>Thu, 26 Sep 2019 08:38:49 +0000</pubDate>
				<category><![CDATA[excel c#]]></category>
		<category><![CDATA[data driven testing using excel c#]]></category>
		<category><![CDATA[excel operations in c#]]></category>
		<category><![CDATA[how to interact with excel]]></category>
		<category><![CDATA[set data in excel]]></category>
		<category><![CDATA[set data in excel using column name]]></category>
		<category><![CDATA[using column name to write data]]></category>
		<guid isPermaLink="false">http://automationtesting.in/?p=2112</guid>

					<description><![CDATA[<p>Write Data in Excel Using Column Number in C#, We will discuss about how to write data in excel using column name in C#. Usually we will use the excel sheet to maintain the test data. We might get doubt that why we need to put the test data/results in excel. If an application feed [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://automationtesting.in/write-data-excel-using-column-name-c/">Write Data in Excel Using Column Name in C#</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script><br />
Write Data in Excel Using Column Number in C#, We will discuss about how to write data in excel using column name in C#. Usually we will use the excel sheet to maintain the test data. We might get doubt that why we need to put the test data/results in excel. If an application feed so much of data to be need to test; then we will manage those data using external sources like text file, xml file and excel file etc…. Among these; Excel is very user friendly that we can organize the data very easily and we can read and write the data how we want. So, we mostly use excel to maintain the test data and results.</p>
<div class="post-video"><iframe loading="lazy" title="6. How to Write Data To Excel using Column Name in Selenium Webdriver C# | Excel Write in C#" width="1165" height="655" src="https://www.youtube.com/embed/YFb5cBCox5M?wmode=transparent&#038;fs=1"  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
<p>So, if you want to write huge number of test data in excel sheet to feed to the application then we need to know how many rows and columns are there in the excel. If you know exact information about the test data then only we can get the information from the excel in proper way. In this blog we will use to write data in excel using column name in C#. To do this, we need to create a console application in Visual studio and Install Microsoft.Office.Interop.Excel Nuget package.</p>
<p>For this we need to have the below pre-requisites:</p>
<ol>
<li>Create a Console Application in Visual Studio</li>
<li>Install <b>Microsoft.Office.Interop.Excel</b>Nuget Package by following below steps
<ul>
<li>Under your Console Application, Right Click on reference, Click on Manage Nuget Package</li>
<li>Go to Browse</li>
<li>Under Browse search for “Microsoft.Office.Interop.Excel”</li>
<li>click on “Microsoft.Office.Interop.Excel” and then Click Install</li>
<li>Make sure that your package got installed and appears under References folder under your Console App.</li>
</ul>
</ol>
<p><b>What is Microsoft.Office.Interop.Excel Nuget package?</b></p>
<p>By using this Nuget package we can interact with the excel like reading data from the Excel or writing data to excel and you can find row count/column count.</p>
<p>To Interact with our Nuget, we need to add the below using statement:<br />
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script><br />
<b>Using xl = Microsoft.Office.Interop.Excel;</b></p>
<p><b>Below are the classes will use to write the column name:</b></p>
<ol>
<li>ExcelApiTest</li>
<li>CheckExcel</li>
</ol>
<p><b>Below are the Interfaces will use to Set the cell data using Microsoft.Interop.Excel package:</b></p>
<ol>
<li>Xl.Application</li>
<li>Xl.Workbooks</li>
<li>Xl.Workbook</li>
</ol>
<p><b>Below collection is needed to create a Hash table:</b></p>
<ol>
<li>Using System.Collections</li>
</ol>
<p><b>Below Constructors are called to Interact with the User defined Excel sheet:</b></p>
<ol>
<li>ExcelApiTest</li>
</ol>
<p><b>Below are the Methods will use to set the cell data using column name:</b></p>
<ol>
<li>OpenExcel() //Establish the connection</li>
<li>CloseExcel()//Closes all the connections</li>
<li>SetCellData()</li>
</ol>
<p>Following is the code, we have used some Interfaces and methods to create connections, setting the cell data using column name and closing the connections.</p>
<pre class="brush: csharp; title: ; notranslate">
using System;
using System.Collections;
using System.Runtime.InteropServices;
using xl = Microsoft.Office.Interop.Excel;

namespace CSharpPractice
{
    class ExcelApiTest
    {
        xl.Application xlApp = null;
        xl.Workbooks workbooks = null;
        xl.Workbook workbook = null;
        Hashtable sheets;
        public string xlFilePath;

        public ExcelApiTest(string xlFilePath)
        {
            this.xlFilePath = xlFilePath;
        }

        public void OpenExcel()
        {
            xlApp = new xl.Application();
            workbooks = xlApp.Workbooks;
            workbook = workbooks.Open(xlFilePath);
            sheets = new Hashtable();
            int count = 1;
            // Storing worksheet names in Hashtable.
            foreach (xl.Worksheet sheet in workbook.Sheets)
            {
                sheets&#x5B;count] = sheet.Name;
                count++;
            }
        }

        public void CloseExcel()
        {
            workbook.Close(false, xlFilePath, null); // Close the connection to workbook
            Marshal.FinalReleaseComObject(workbook); // Release unmanaged object references.
            workbook = null;

            workbooks.Close();
            Marshal.FinalReleaseComObject(workbooks);
            workbooks = null;

            xlApp.Quit();
            Marshal.FinalReleaseComObject(xlApp);
            xlApp = null;
        }

       public bool SetCellData(string sheetName, string colName, int rowNumber, string value)
        {
            OpenExcel();

            int sheetValue = 0;
            int colNumber = 0;

            try
            {
                if (sheets.ContainsValue(sheetName))
                {
                    foreach (DictionaryEntry sheet in sheets)
                    {
                        if (sheet.Value.Equals(sheetName))
                        {
                            sheetValue = (int)sheet.Key;
                        }
                    }

                    xl.Worksheet worksheet = null;
                    worksheet = workbook.Worksheets&#x5B;sheetValue] as xl.Worksheet;
                    xl.Range range = worksheet.UsedRange;

                    for (int i = 1; i &lt;= range.Columns.Count; i++)
                    {
                        string colNameValue = Convert.ToString((range.Cells&#x5B;1,i] as xl.Range).Value2);
                        if (colNameValue.ToLower() == colName.ToLower())
                        {
                            colNumber = i;
                            break;
                        }
                    }

                    range.Cells&#x5B;rowNumber, colNumber] = value;

                    workbook.Save();
                    Marshal.FinalReleaseComObject(worksheet);
                    worksheet = null;

                    CloseExcel();
                }
            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }

    }
</pre>
<p>Below is a sample program which will call the methods from the above program to set the cell data using column name from any excel sheet.</p>
<pre class="brush: csharp; title: ; notranslate">
﻿using System;

namespace CSharpPractice
{
    class CheckExcel
    {
        static void Main(string&#x5B;] args)
        {
            string xlFilePath = &quot;D:/ExcelFiles/TestData.xlsx&quot;;

            ExcelApiTest eat = new ExcelApiTest(xlFilePath);
            eat.SetCellData(&quot;Credentials&quot;, &quot;NoOfAttempts&quot;, 5, &quot;20&quot;);


        }

    }
}
</pre>
<p><a href="https://youtu.be/YFb5cBCox5M">Please watch the Youtube video for better understanding.</a></p>
<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<div id="themify_builder_content-2112" data-postid="2112" class="themify_builder_content themify_builder_content-2112 themify_builder themify_builder_front">

	</div>
<!-- /themify_builder_content --><p>The post <a rel="nofollow" href="https://automationtesting.in/write-data-excel-using-column-name-c/">Write Data in Excel Using Column Name in C#</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://automationtesting.in/write-data-excel-using-column-name-c/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Get Data from Excel Using Column Name in C#</title>
		<link>https://automationtesting.in/get-data-from-excel-using-column-name-in-c/</link>
					<comments>https://automationtesting.in/get-data-from-excel-using-column-name-in-c/#respond</comments>
		
		<dc:creator><![CDATA[]]></dc:creator>
		<pubDate>Sun, 22 Sep 2019 05:08:03 +0000</pubDate>
				<category><![CDATA[excel c#]]></category>
		<category><![CDATA[data driven testing using c#]]></category>
		<category><![CDATA[excel operations in c#]]></category>
		<category><![CDATA[get data from column name]]></category>
		<category><![CDATA[get data from excel]]></category>
		<category><![CDATA[Get data in excel file]]></category>
		<category><![CDATA[how to get data from excel]]></category>
		<guid isPermaLink="false">http://automationtesting.in/?p=2040</guid>

					<description><![CDATA[<p>Get Data from excel using column name in c#, We will discuss about how to get data from excel using column name in C#. Usually we will use the excel sheet to maintain the test data. We might get doubt that why we need to put the test data/results in excel. If an application need [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://automationtesting.in/get-data-from-excel-using-column-name-in-c/">Get Data from Excel Using Column Name in C#</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script><br />
Get Data from excel using column name in c#, We will discuss about how to get data from excel using column name in C#. Usually we will use the excel sheet to maintain the test data. We might get doubt that why we need to put the test data/results in excel. If an application need so much of data to be feed to test; then we will manage those data using external sources like text file, xml file and excel file etc…. Among these; Excel is very user friendly that we can organize the data very easily and we can read and write the data how we want. So, we mostly use excel to maintain the test data and results.</p>
<div class="post-video"><iframe loading="lazy" title="4. How to Read Data From Excel using Column Name in Selenium Webdriver C# | Excel Read in C#" width="1165" height="655" src="https://www.youtube.com/embed/hCRY0tRJaec?wmode=transparent&#038;fs=1"  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
<p>So, if you want to read huge number of test data from the excel sheet to feed to the application then we need to know how many rows and columns are there in the excel. If you know exact information about the test data then only we can get the information from the excel in proper way. In this blog we will use to get how to read the data from excel sheet. To do this, we need to create a console application in Visual studio and Install Microsoft.Office.Interop.Excel Nuget package.</p>
<p>For this we need to have the below pre-requisites:</p>
<ol>
<li>Create a Console Application in Visual Studio</li>
<li>Install <strong>Office.Interop.Excel</strong> Nuget Package by following below steps
<ol>
<li>Under your Console Application, Right Click on reference, Click on Manage Nuget Package</li>
<li>Go to Browse</li>
<li>Under Browse search for “Microsoft.Office.Interop.Excel”</li>
<li>click on “Microsoft.Office.Interop.Excel” and then Click Install</li>
<li>Make sure that your package got installed and appears under References folder under your Console App.</li>
</ol>
</li>
</ol>
<p>&nbsp;</p>
<p><strong>What is Microsoft.Office.Interop.Excel Nuget package?</strong></p>
<p>By using this Nuget package we can interact with the excel like reading data from the Excel or writing data to the excel and you can find row count/column count.</p>
<p><strong>To Interact with our Nuget, we need to add the below using statement:</strong></p>
<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script><br />
<strong>Using xl = Microsoft.Office.Interop.Excel;</strong></p>
<p><strong>Below are the classes will use to get the CellData using Column name:</strong></p>
<ol>
<li>ExcelApiTest</li>
<li>CheckExcel</li>
</ol>
<p><strong>Below are the Interfaces will use to get the CellData using Microsoft.Interop.Excel package:</strong></p>
<ol>
<li>Application</li>
<li>Workbooks</li>
<li>Workbook</li>
</ol>
<p><strong>Below collection is needed to create a Hash table:</strong></p>
<ol>
<li>Using System.Collections</li>
</ol>
<p><strong>Below Constructors are called to Interact with the User defined Excel sheet:</strong></p>
<ol>
<li>ExcelApiTest</li>
</ol>
<p><strong>Below are the Methods will use to get the CellData using Column name:</strong></p>
<ol>
<li>OpenExcel() //Establish the connection</li>
<li>CloseExcel()//Closes all the connections</li>
<li>GetCellData()</li>
</ol>
<p>Following is the code, we have used some Interfaces and methods to create connections, getting the cell data using column name and closing the connections.</p>
<pre class="brush: csharp; title: ; notranslate">
using System;
using System.Collections;
using System.Runtime.InteropServices;
using xl = Microsoft.Office.Interop.Excel;

namespace CSharpPractice
{
    class ExcelApiTest
    {
        xl.Application xlApp = null;
        xl.Workbooks workbooks = null;
        xl.Workbook workbook = null;
        Hashtable sheets;
        public string xlFilePath;

        public ExcelApiTest(string xlFilePath)
        {
            this.xlFilePath = xlFilePath;
        }

        public void OpenExcel()
        {
            xlApp = new xl.Application();
            workbooks = xlApp.Workbooks;
            workbook = workbooks.Open(xlFilePath);
            sheets = new Hashtable();
            int count = 1;
            // Storing worksheet names in Hashtable.
            foreach (xl.Worksheet sheet in workbook.Sheets)
            {
                sheets&#x5B;count] = sheet.Name;
                count++;
            }
        }

        public void CloseExcel()
        {
            workbook.Close(false, xlFilePath, null); // Close the connection to workbook
            Marshal.FinalReleaseComObject(workbook); // Release unmanaged object references.
            workbook = null;

            workbooks.Close();
            Marshal.FinalReleaseComObject(workbooks);
            workbooks = null;

            xlApp.Quit();
            Marshal.FinalReleaseComObject(xlApp);
            xlApp = null;
        }

        public string GetCellData(string sheetName, string colName, int rowNumber)
        {
            OpenExcel();

            string value = string.Empty;
            int sheetValue = 0;
            int colNumber = 0;

            if (sheets.ContainsValue(sheetName))
            {
                foreach (DictionaryEntry sheet in sheets)
                {
                    if (sheet.Value.Equals(sheetName))
                    {
                        sheetValue = (int)sheet.Key;
                    }
                }
                xl.Worksheet worksheet = null;
                worksheet = workbook.Worksheets&#x5B;sheetValue] as xl.Worksheet;
                xl.Range range = worksheet.UsedRange;

                for (int i = 1; i &lt;= range.Columns.Count; i++)
                {
                    string colNameValue = Convert.ToString((range.Cells&#x5B;1,i] as xl.Range).Value2);

                    if (colNameValue.ToLower() == colName.ToLower())
                    {
                        colNumber = i;
                        break;
                    }
                }

                value = Convert.ToString((range.Cells&#x5B;rowNumber, colNumber] as xl.Range).Value2);
                Marshal.FinalReleaseComObject(worksheet);
                worksheet = null;
            }
            CloseExcel();
            return value;
        }
</pre>
<p>Below is a sample program which will call the methods from the above program to get data from excel using column name from any excel sheet.</p>
<pre class="brush: csharp; title: ; notranslate">
using System;

namespace CSharpPractice
{
    class CheckExcel
    {
        static void Main(string&#x5B;] args)
        {
            string xlFilePath = &quot;D:/ExcelFiles/TestData.xlsx&quot;;

            ExcelApiTest eat = new ExcelApiTest(xlFilePath);

            cellValue = eat.GetCellData(&quot;Sheet1&quot;, &quot;FirstName&quot;, 4);
            Console.WriteLine(&quot;Cell Value using Column Name: &quot; + cellValue);


            Console.Read();
        }

    }
}
</pre>
<p><a href="https://www.youtube.com/watch?v=hCRY0tRJaec">Please watch the Youtube video for better understanding.</a><br />
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<div id="themify_builder_content-2040" data-postid="2040" class="themify_builder_content themify_builder_content-2040 themify_builder themify_builder_front">

	</div>
<!-- /themify_builder_content --><p>The post <a rel="nofollow" href="https://automationtesting.in/get-data-from-excel-using-column-name-in-c/">Get Data from Excel Using Column Name in C#</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://automationtesting.in/get-data-from-excel-using-column-name-in-c/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Get Data from Excel Using Column Number in C#</title>
		<link>https://automationtesting.in/get-data-from-excel-using-column-number-in-c/</link>
					<comments>https://automationtesting.in/get-data-from-excel-using-column-number-in-c/#respond</comments>
		
		<dc:creator><![CDATA[]]></dc:creator>
		<pubDate>Sun, 22 Sep 2019 05:02:12 +0000</pubDate>
				<category><![CDATA[excel c#]]></category>
		<category><![CDATA[data driven framework in selenium]]></category>
		<category><![CDATA[data driven testing using in excel c#]]></category>
		<category><![CDATA[excel operations in c#]]></category>
		<category><![CDATA[Get data in excel file]]></category>
		<category><![CDATA[Get data using column number]]></category>
		<category><![CDATA[how to interact with excel]]></category>
		<category><![CDATA[Using column number retrieving data]]></category>
		<guid isPermaLink="false">http://automationtesting.in/?p=2024</guid>

					<description><![CDATA[<p>Get Data from excel using column number in c#, We will discuss about how to get data from excel using column number in C#. Usually we will use the excel sheet to maintain the test data. We might get doubt that why we need to put the test data/results in excel. If an application need [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://automationtesting.in/get-data-from-excel-using-column-number-in-c/">Get Data from Excel Using Column Number in C#</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script><br />
Get Data from excel using column number in c#, We will discuss about how to get data from excel using column number in C#. Usually we will use the excel sheet to maintain the test data. We might get doubt that why we need to put the test data/results in excel. If an application need so much of data to be feed to test; then we will manage those data using external sources like text file, xml file and excel file etc…. Among these; Excel is very user friendly that we can organize the data very easily and we can read and write the data how we want. So, we mostly use excel to maintain the test data and results.</p>
<div class="post-video"><iframe loading="lazy" title="3. How to Read Data From Excel using Column Number in Selenium Webdriver C# | Excel Read in C#" width="1165" height="655" src="https://www.youtube.com/embed/pbGCsk7aRjE?wmode=transparent&#038;fs=1"  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
<p>So, if you want to read huge number of test data from the excel sheet to feed to the application then we need to know how many rows and columns are there in the excel. If you know exact information about the test data then only we can get the information from the excel in proper way. In this blog we will use to get how to get the data from excel sheet using column number in c#. To do this, we need to create a console application in Visual studio and Install Microsoft.Office.Interop.Excel Nuget package.</p>
<p>For this we need to have the below pre-requisites:</p>
<ol>
<li>Create a Console Application in Visual Studio</li>
<li>Install <strong>Office.Interop.Excel</strong> Nuget Package by following below steps
<ul>
<li>Under your Console Application, Right Click on reference, Click on Manage Nuget Package</li>
<li>Go to Browse</li>
<li>Under Browse search for “Microsoft.Office.Interop.Excel”</li>
<li>click on “Microsoft.Office.Interop.Excel” and then Click Install</li>
<li>Make sure that your package got installed and appears under References folder under your Console App.</li>
</ul>
</li>
</ol>
<p><strong>What is Microsoft.Office.Interop.Excel Nuget package?</strong></p>
<p>By using this Nuget package we can interact with the excel like reading data from the Excel or writing data to the excel and you can find row count/column count.</p>
<p>To Interact with our Nuget, we need to add the below using statement:<br />
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<p><strong>Using xl = Microsoft.Office.Interop.Excel;</strong></p>
<p><strong>Below are the classes will use to get the CellData using Column number:</strong></p>
<ol>
<li>ExcelApiTest</li>
<li>CheckExcel</li>
</ol>
<p><strong>Below are the Interfaces will use to get the CellData using Microsoft.Interop.Excel package:</strong></p>
<ol>
<li>Application</li>
<li>Workbooks</li>
<li>Workbook</li>
</ol>
<p><strong>Below collection is needed to create a Hash table:</strong></p>
<ol>
<li>Using System.Collections</li>
</ol>
<p><strong>Below Constructors are called to Interact with the User defined Excel sheet:</strong></p>
<ol>
<li>ExcelApiTest</li>
</ol>
<p><strong>Below are the Methods will use to get the CellData using Column number:</strong></p>
<ol>
<li>OpenExcel() //Establish the connection</li>
<li>CloseExcel()//Closes all the connections</li>
<li>GetCellData()</li>
</ol>
<p>Following is the code, we have used some Interfaces and methods to create connections, getting the cell data using column number and closing the connections.</p>
<pre class="brush: csharp; title: ; notranslate">
using System;
using System.Collections;
using System.Runtime.InteropServices;
using xl = Microsoft.Office.Interop.Excel;

namespace CSharpPractice
{
    class ExcelApiTest
    {
        xl.Application xlApp = null;
        xl.Workbooks workbooks = null;
        xl.Workbook workbook = null;
        Hashtable sheets;
        public string xlFilePath;

        public ExcelApiTest(string xlFilePath)
        {
            this.xlFilePath = xlFilePath;
        }

        public void OpenExcel()
        {
            xlApp = new xl.Application();
            workbooks = xlApp.Workbooks;
            workbook = workbooks.Open(xlFilePath);
            sheets = new Hashtable();
            int count = 1;
            // Storing worksheet names in Hashtable.
            foreach (xl.Worksheet sheet in workbook.Sheets)
            {
                sheets&#x5B;count] = sheet.Name;
                count++;
            }
        }

        public void CloseExcel()
        {
            workbook.Close(false, xlFilePath, null); // Close the connection to workbook
            Marshal.FinalReleaseComObject(workbook); // Release unmanaged object references.
            workbook = null;

            workbooks.Close();
            Marshal.FinalReleaseComObject(workbooks);
            workbooks = null;

            xlApp.Quit();
            Marshal.FinalReleaseComObject(xlApp);
            xlApp = null;
        }
        public string GetCellData(string sheetName, int colNumber, int rowNumber)
        {
            OpenExcel();

            string value = string.Empty;
            int sheetValue = 0;

            if (sheets.ContainsValue(sheetName))
            {
                foreach (DictionaryEntry sheet in sheets)
                {
                    if (sheet.Value.Equals(sheetName))
                    {
                        sheetValue = (int)sheet.Key;
                    }
                }
                xl.Worksheet worksheet = null;
                worksheet = workbook.Worksheets&#x5B;sheetValue] as xl.Worksheet;
                xl.Range range = worksheet.UsedRange;

                value = Convert.ToString((range.Cells&#x5B;rowNumber, colNumber] as xl.Range).Value2);
                Marshal.FinalReleaseComObject(worksheet);
                worksheet = null;
            }
            CloseExcel();
            return value;
        }
    }
}
</pre>
<p>Below is a sample program which will call the methods from the above program to get the cell data using column number from any excel sheet.</p>
<pre class="brush: csharp; title: ; notranslate">
using System;

namespace CSharpPractice
{
    class CheckExcel
    {
        static void Main(string&#x5B;] args)
        {
            string xlFilePath = &amp;quot;D:/ExcelFiles/TestData.xlsx&amp;quot;;

            ExcelApiTest eat = new ExcelApiTest(xlFilePath);

            string cellValue = eat.GetCellData(&amp;quot;Sheet1&amp;quot;, 1, 6);
            Console.WriteLine(&amp;quot;Cell Value using Column Number: &amp;quot; + cellValue);

            Console.Read();

        }

    }
}
</pre>
<p><a href="https://www.youtube.com/watch?v=pbGCsk7aRjE">Please watch the Youtube video for better understanding.</a></p>
<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<div id="themify_builder_content-2024" data-postid="2024" class="themify_builder_content themify_builder_content-2024 themify_builder themify_builder_front">

	</div>
<!-- /themify_builder_content --><p>The post <a rel="nofollow" href="https://automationtesting.in/get-data-from-excel-using-column-number-in-c/">Get Data from Excel Using Column Number in C#</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://automationtesting.in/get-data-from-excel-using-column-number-in-c/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Column Count in Excel Using C#</title>
		<link>https://automationtesting.in/column-count-in-excel-using-selenium-c/</link>
					<comments>https://automationtesting.in/column-count-in-excel-using-selenium-c/#respond</comments>
		
		<dc:creator><![CDATA[]]></dc:creator>
		<pubDate>Sun, 22 Sep 2019 04:47:22 +0000</pubDate>
				<category><![CDATA[excel c#]]></category>
		<category><![CDATA[column count]]></category>
		<category><![CDATA[data driven framework in selenium]]></category>
		<category><![CDATA[data driven framework using excel in selenium]]></category>
		<category><![CDATA[data driven testing using excel c#]]></category>
		<category><![CDATA[excel read write in selenium]]></category>
		<category><![CDATA[finding column count in excel]]></category>
		<category><![CDATA[how to get column count]]></category>
		<category><![CDATA[how to get column count in excel]]></category>
		<category><![CDATA[how to interact with excel]]></category>
		<category><![CDATA[how to read excel data using c#]]></category>
		<category><![CDATA[read excel data]]></category>
		<category><![CDATA[read excel file]]></category>
		<guid isPermaLink="false">http://automationtesting.in/?p=1995</guid>

					<description><![CDATA[<p>Column Count in Excel Using C#, We will discuss about how to find column count in excel using C#. Usually we will use the excel sheet to maintain the test data. We might get doubt that why we need to put the test data/results in excel. If an application need so much of data to [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://automationtesting.in/column-count-in-excel-using-selenium-c/">Column Count in Excel Using C#</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<p>Column Count in Excel Using C#, We will discuss about how to find column count in excel using C#. Usually we will use the excel sheet to maintain the test data. We might get doubt that why we need to put the test data/results in excel. If an application need so much of data to be feed to test; then we will manage those data using external sources like text file, xml file and excel file etc…. Among these; Excel is very user friendly that we can organize the data very easily and we can read and write the data how we want. So, we mostly use excel to maintain the test data and results.</p>
<div class="post-video"><iframe loading="lazy" title="2. How to Find Column Count in Excel using Selenium Webdriver C# | Excel Read in C#|Data Driven Test" width="1165" height="655" src="https://www.youtube.com/embed/h_GGXj-MOjE?wmode=transparent&#038;fs=1"  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
<p>So, if you want to read huge number of test data from the excel sheet to feed to the application then we need to know how many rows and columns are there in the excel. If you know exact information about the test data then only we can get the information from the excel in proper way. In this blog we will use to get the Column count from the excel sheet. To do this, we need to create a console application in Visual studio and Install Microsoft.Office.Interop.Excel Nuget package.</p>
<p><strong>For this we need to have the following prerequisites:</strong></p>
<ol>
<li>Create a Console Application in Visual Studio</li>
<li>Install <strong>Office.Interop.Excel</strong> Nuget Package by following below steps
<ul>
<li>Under your Console Application, Right Click on reference, Click on Manage Nuget Package</li>
<li>Go to Browse</li>
<li>Under Browse search for “Microsoft.Office.Interop.Excel”</li>
<li>click on “Microsoft.Office.Interop.Excel” and then Click Install</li>
<li>Make sure that your package got installed and appears under References folder under your Console App.</li>
</ul>
</li>
</ol>
<p><strong>What is Microsoft.Office.Interop.Excel Nuget package?</strong></p>
<p>By using this Nuget package we can interact with the excel like reading data from the Excel or writing data to the excel and you can find row count/column count.</p>
<p>To Interact with our Nuget, we need to add the below using statement:<br />
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<p><strong>Using xl = Microsoft.Office.Interop.Excel;</strong></p>
<p><strong> </strong><strong>Below are the classes will use to read the Column count:</strong></p>
<ol>
<li>ExcelApiTest</li>
<li>CheckExcel</li>
</ol>
<p><strong>Below are the Interfaces will use to read the Column count using Microsoft.Interop.Excel package:</strong></p>
<ol>
<li>Application</li>
<li>Workbooks</li>
<li>Workbook</li>
</ol>
<p><strong>Below collection is needed to create a Hash table:</strong></p>
<ol>
<li>Using System.Collections</li>
</ol>
<p><strong>Below Constructors are called to Interact with the User defined Excel sheet:</strong></p>
<ol>
<li>ExcelApiTest</li>
</ol>
<p><strong>Below are the Methods will use to read the Column count:</strong></p>
<ol>
<li>OpenExcel() //Establish the connection</li>
<li>CloseExcel()//Closes all the connections</li>
<li>GetColumnCount()</li>
</ol>
<p>Following is the code, we have used some Interfaces and methods to create connections, getting the column count and closing the connections.</p>
<pre class="brush: csharp; title: ; notranslate">
using System;
using System.Collections;
using System.Runtime.InteropServices;
using xl = Microsoft.Office.Interop.Excel;

namespace CSharpPractice
{
    class ExcelApiTest
    {
        xl.Application xlApp = null;
        xl.Workbooks workbooks = null;
        xl.Workbook workbook = null;
        Hashtable sheets;
        public string xlFilePath;

        public ExcelApiTest(string xlFilePath)
        {
            this.xlFilePath = xlFilePath;
        }

        public void OpenExcel()
        {
            xlApp = new xl.Application();
            workbooks = xlApp.Workbooks;
            workbook = workbooks.Open(xlFilePath);
            sheets = new Hashtable();
            int count = 1;
            // Storing worksheet names in Hashtable.
            foreach (xl.Worksheet sheet in workbook.Sheets)
            {
                sheets&#x5B;count] = sheet.Name;
                count++;
            }
        }

        public void CloseExcel()
        {
            workbook.Close(false, xlFilePath, null); // Close the connection to workbook
            Marshal.FinalReleaseComObject(workbook); // Release unmanaged object references.
            workbook = null;

            workbooks.Close();
            Marshal.FinalReleaseComObject(workbooks);
            workbooks = null;

            xlApp.Quit();
            Marshal.FinalReleaseComObject(xlApp);
            xlApp = null;
        }

        public int GetColumnCount(string sheetName)
        {
            OpenExcel();

            int columnCount = 0;
            int sheetValue = 0;

            if (sheets.ContainsValue(sheetName))
            {
                foreach (DictionaryEntry sheet in sheets)
                {
                    if (sheet.Value.Equals(sheetName))
                    {
                        sheetValue = (int)sheet.Key;
                    }
                }
                xl.Worksheet worksheet = workbook.Worksheets&#x5B;sheetValue] as xl.Worksheet;
                xl.Range range = worksheet.UsedRange;
                columnCount = range.Columns.Count;
            }
            CloseExcel();

            return columnCount;
        }
    }
}
</pre>
<p>Below is a sample program which will call the methods from the above program to get the column count from any excel sheet.</p>
<pre class="brush: csharp; title: ; notranslate">
using System;

namespace CSharpPractice
{
    class CheckExcel
    {
        static void Main(string&#x5B;] args)
        {
            string xlFilePath = &amp;amp;amp;amp;quot;D:/ExcelFiles/TestData.xlsx&amp;amp;amp;amp;quot;;

            ExcelApiTest eat = new ExcelApiTest(xlFilePath);
            
            int colCount = eat.GetColumnCount(&amp;amp;amp;amp;quot;Sheet1&amp;amp;amp;amp;quot;);
            Console.WriteLine(&amp;amp;amp;amp;quot;Total Number of Columns: &amp;amp;amp;amp;quot; + colCount);

            Console.Read();
        }

    }
}
</pre>
<p><a href="https://www.youtube.com/watch?v=h_GGXj-MOjE">Please watch the Youtube video for better understanding.</a></p>
<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<div id="themify_builder_content-1995" data-postid="1995" class="themify_builder_content themify_builder_content-1995 themify_builder themify_builder_front">

	</div>
<!-- /themify_builder_content --><p>The post <a rel="nofollow" href="https://automationtesting.in/column-count-in-excel-using-selenium-c/">Column Count in Excel Using C#</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://automationtesting.in/column-count-in-excel-using-selenium-c/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Row Count in Excel Using C#</title>
		<link>https://automationtesting.in/row-count-excel-using-c/</link>
					<comments>https://automationtesting.in/row-count-excel-using-c/#respond</comments>
		
		<dc:creator><![CDATA[Krishna Sakinala]]></dc:creator>
		<pubDate>Mon, 16 Sep 2019 13:16:40 +0000</pubDate>
				<category><![CDATA[excel c#]]></category>
		<category><![CDATA[data driven framework in selenium]]></category>
		<category><![CDATA[data driven framework using excel in selenium]]></category>
		<category><![CDATA[data driven testing using excel c#]]></category>
		<category><![CDATA[excel read write c#]]></category>
		<category><![CDATA[excel read write in selenium]]></category>
		<category><![CDATA[find row count in excel]]></category>
		<category><![CDATA[how to interact with excel]]></category>
		<category><![CDATA[how to read data from excel c#]]></category>
		<category><![CDATA[how to read excel data using c#]]></category>
		<category><![CDATA[how to read excel file in selenium webdriver]]></category>
		<category><![CDATA[how to read excel file using c#]]></category>
		<category><![CDATA[read excel data]]></category>
		<category><![CDATA[read excel file]]></category>
		<category><![CDATA[row count in excel]]></category>
		<guid isPermaLink="false">http://automationtesting.in/?p=1968</guid>

					<description><![CDATA[<p>Row Count in Excel Using C#, we will discuss about how to find row count in excel using C#. Usually we will use the excel sheet to maintain the test data. We might get doubt that why we need to put the test data/results in excel. If an application needs so much of data to [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://automationtesting.in/row-count-excel-using-c/">Row Count in Excel Using C#</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script><br />
Row Count in Excel Using C#, we will discuss about how to find row count in excel using C#. Usually we will use the excel sheet to maintain the test data. We might get doubt that why we need to put the test data/results in excel. If an application needs so much of data to be fed to test; then we will manage those data using external sources like text file, xml file and excel file etc…. Among these; Excel is very user friendly that we can organize the data very easily and we can read and write the data how we want. So, we mostly use excel to maintain the test data and results.</p>
<div class="post-video"><iframe loading="lazy" title="1. How to Find Row Count in Excel using  Selenium WebDriver C# | Excel Read in C# | Data Driven Test" width="1165" height="655" src="https://www.youtube.com/embed/2FBvkQ9fY1c?wmode=transparent&#038;fs=1"  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
<p>So, if you want to read a huge number of test data from the excel sheet to feed to the application then we need to know how many rows and columns are there in the excel. If you know the exact information about the test data then only we can get the information from the excel in proper way. In this blog we will use to get the row count from the excel sheet. To do this, we need to create a console application in Visual studio and Install <strong>Microsoft.Office.Interop.Excel</strong> Nuget package.</p>
<p><strong>For this we need to have the following prerequisites:</strong></p>
<ol>
<li>Create a Console Application in Visual Studio.</li>
<li>Install <strong>Microsoft.Office.Interop.Excel Nuget</strong> Package by following below steps.
<ul>
<li>Under your Console Application, Right Click on reference, Click on Manage Nuget Package</li>
<li>Go to Browse</li>
<li>Under Browse search for “Microsoft.Office.Interop.Excel”</li>
<li>click on “Microsoft.Office.Interop.Excel” and then Click Install</li>
<li>Make sure that your package got installed and appears under References folder under your Console App.</li>
</ul>
</li>
</ol>
<p>What is Microsoft.Office.Interop.Excel Nuget package?<br />
By using this Nuget package we can interact with the excel like reading data from Excel or writing data to excel and you can find row count/column count.</p>
<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script><br />
To Interact with our Nuget, we need to add the below using statement:</p>
<pre class="brush: csharp; title: ; notranslate">
using xl = Microsoft.Office.Interop.Excel;
</pre>
<p>Below are the classes will use to read the Row count:</p>
<ol>
<li>ExcelApiTest</li>
<li>CheckExcel</li>
</ol>
<p>Following are the Interfaces will use to read the Row count using <strong>Microsoft.Office.Interop.Excel</strong> package:</p>
<ol>
<li>Application</li>
<li>Workbooks</li>
<li>Workbook</li>
</ol>
<p>Following collection is needed to create a Hash table:</p>
<ol>
<li>Using System.Collections</li>
</ol>
<p>Following Constructors are called to Interact with the User defined Excel sheet:</p>
<ol>
<li>ExcelApiTest</li>
</ol>
<p>Following are the Methods will write to read the row count:</p>
<ol>
<li>OpenExcel() //Establish the connection</li>
<li>CloseExcel()//Closes all the connections</li>
<li>GetRowCount()</li>
</ol>
<p>Following is the code, we have used some Interfaces and methods to create connections, getting the row count and closing the connections.</p>
<pre class="brush: csharp; title: ; notranslate">
using System;
using System.Collections;
using System.Runtime.InteropServices;
using xl = Microsoft.Office.Interop.Excel;

namespace CSharpPractice
{
    class ExcelApiTest
    {
        xl.Application xlApp = null;
        xl.Workbooks workbooks = null;
        xl.Workbook workbook = null;
        Hashtable sheets;
        public string xlFilePath;

        public ExcelApiTest(string xlFilePath)
        {
            this.xlFilePath = xlFilePath;
        }

        public void OpenExcel()
        {
            xlApp = new xl.Application();
            workbooks = xlApp.Workbooks;
            workbook = workbooks.Open(xlFilePath);
            sheets = new Hashtable();
            int count = 1;
            // Storing worksheet names in Hashtable.
            foreach (xl.Worksheet sheet in workbook.Sheets)
            {
                sheets&#x5B;count] = sheet.Name;
                count++;
            }
        }

        public void CloseExcel()
        {
            workbook.Close(false, xlFilePath, null); // Close the connection to workbook
            Marshal.FinalReleaseComObject(workbook); // Release unmanaged object references.
            workbook = null;

            workbooks.Close();
            Marshal.FinalReleaseComObject(workbooks);
            workbooks = null;

            xlApp.Quit();
            Marshal.FinalReleaseComObject(xlApp);
            xlApp = null;
        }

        public int GetRowCount(string sheetName)
        {
            OpenExcel();
            
            int rowCount = 0;
            int sheetValue = 0;

            if (sheets.ContainsValue(sheetName))
            {
                foreach (DictionaryEntry sheet in sheets) // Iterate over Hashtable
                {
                    if (sheet.Value.Equals(sheetName))
                    {
                        sheetValue = (int)sheet.Key;
                    }
                }

                // Getting particular worksheet using index/key from workbook
                xl.Worksheet worksheet = workbook.Worksheets&#x5B;sheetValue] as xl.Worksheet;
                xl.Range range = worksheet.UsedRange; // Range of cells which is having content.
                rowCount = range.Rows.Count;
            }

            CloseExcel();

            return rowCount;
        }
    }
}
</pre>
<p>Below is a sample program which will call the methods from the above program to get the row count from any excel sheet.</p>
<pre class="brush: csharp; title: ; notranslate">
using System;

namespace CSharpPractice
{
    class CheckExcel
    {
        static void Main(string&#x5B;] args)
        {
            string xlFilePath = &quot;D:/ExcelFiles/TestData.xlsx&quot;;

            ExcelApiTest eat = new ExcelApiTest(xlFilePath);
            int rowCount = eat.GetRowCount(&quot;Sheet1&quot;);

            Console.WriteLine(&quot;Total Number of Rows : &quot; + rowCount);

            Console.Read();
        }
    }
}
</pre>
<p><a href="https://www.youtube.com/watch?v=2FBvkQ9fY1c">Please watch the Youtube video for better understanding.</a></p>
<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<div id="themify_builder_content-1968" data-postid="1968" class="themify_builder_content themify_builder_content-1968 themify_builder themify_builder_front">

	</div>
<!-- /themify_builder_content --><p>The post <a rel="nofollow" href="https://automationtesting.in/row-count-excel-using-c/">Row Count in Excel Using C#</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://automationtesting.in/row-count-excel-using-c/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
