How to read single Excel cell value
You need to cast it to a string (not an array of string) since it's a single value.
var cellValue = (string)(excelWorksheet.Cells[10, 2] as Excel.Range).Value;
Pandas: Read specific Excel cell value into a variable
Elaborating on @FLab's comment use something along those lines:
Edit:
Updated the answer to correspond to the updated question that asks how to read some sheets at once.
So by providing sheet_name=None
to read_excel()
you can read all the sheets at once and pandas return a dict
of DataFrames, where the keys are the Excel sheet names.
import pandas as pd
In [10]:
df = pd.read_excel('Book1.xlsx', sheetname=None, header=None)
df
Out[11]:
{u'Sheet1': 0
0 1
1 1, u'Sheet2': 0
0 1
1 2
2 10}
In [13]:
data = df["Sheet1"]
secondary_data = df["Sheet2"]
secondary_data.loc[2,0]
Out[13]:
10
Alternatively, as noted in this post, if your Excel file has several sheets you can pass sheetname
a list of strings, sheet names to parse eg.
df = pd.read_excel('Book1.xlsx', sheetname=["Sheet1", "Sheet2"], header=None)
Credits to user6241235 for digging out the last alternative
Reading particular cell value from excelsheet in python
To access the value for a specific cell you would use:
value = worksheet.cell(row, column)
C# reading Excel cell values using Microsoft.Office.Interop.Excel
Try this:
foreach (Range c in xlRange.Cells)
{
Console.WriteLine("Address: " + c.Address + " - Value: " + c.Value);
}
Output from my test file:
Complete code:
string testingExcel = @"C:\TestingExcel.xlsx";
Application xlApp = new Application();
Workbook xlWorkbook = xlApp.Workbooks.Open(testingExcel, Type.Missing, true);
_Worksheet xlWorksheet = (_Worksheet)xlWorkbook.Sheets[1];
Range xlRange = xlWorksheet.UsedRange;
foreach (Range c in xlRange.Rows.Cells)
{
Console.WriteLine("Address: " + c.Address + " - Value: " + c.Value);
}
xlWorkbook.Close();
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkbook);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlApp);
Edited Input with multiple rows:
Read a single cell from Excel to a string using C# and ASP.NET
After filling DataTable, you can search the row like this:
foreach (DataRow dr in dt.Rows)
{
if (dr["name"] == "fred" && dr["ssn"] == "1234")
{
cell = dr["data"].ToString();
break;
}
}
Related Topics
Determine Assembly Version During a Post-Build Event
How to Loop Through a List<T> and Grab Each Item
Are 2 Dimensional Lists Possible in C#
Button Inside a Winforms Textbox
Why Is It Impossible to Override a Getter-Only Property and Add a Setter
Namespace and Class with the Same Name
Binding Objects Defined in Code-Behind
What Is the Efficiency and Performance of Linq and Lambda Expression in .Net
Visual Studio One Project with Several Dlls as Output
How to Define a Method in Razor
What Is the C# Equivalent of Nan or Isnumeric
Is Configurationmanager.Appsettings Available in .Net Core 2.0
How to Know the Size of the String in Bytes
Does Garbage Collection Run During Debug
Using Mediaelement to Play Video from Stream
.Net Regex Matching $ with the End of the String and Not of Line, Even with Multiline Enabled