Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to get content type of a cell? (Read 2141 times)
Ale
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 14
Joined: May 26th, 2023
How to get content type of a cell?
Sep 30th, 2023 at 10:25am
Print Post  
Hello,

I need to know if a cell contains a formula, a number, a date, a string, etc...
How can I get this information?

Thank you!
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: How to get content type of a cell?
Reply #1 - Oct 2nd, 2023 at 6:31am
Print Post  
Hi,

Try this -

Code
Select All
var cell = activeSheet.Cells[0, 0];

if (cell.Value != null)
{
	Debug.WriteLine(cell.Value.GetType());
	// possible types: bool, double, string, DateTime, TimeSpan, object[]
}

if (cell.Data is string)
{
	var stringData = (string)cell.Data;
	bool isFormula = stringData.StartsWith("=") && stringData.Length > 1;
	if (isFormula)
		Debug.WriteLine("value is calculated");
} 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Ale
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 14
Joined: May 26th, 2023
Re: How to get content type of a cell?
Reply #2 - Oct 11th, 2023 at 7:11am
Print Post  
Ok thank you!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint