Click here to Skip to main content
15,905,616 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How we can find "formula" cells in excel using spire xls using c#?

How we can find "formula" cells in excel using spire xls using c#?

What I have tried:

object test = sheet.Rows[0]["A1"].FormulaValue;
object test1 = sheet.Rows[0]["A1"].Formula;
object test2 = sheet.Rows[0]["A1"].FormulaStringValue;

object test3 = sheet.Rows[0]["A1"].FormulaR1C1;
object test14 = sheet.Rows[0]["A1"].FormulaErrorValue;
object test25 = sheet.Rows[0]["A1"].FormulaNumberValue;
Posted
Updated 1-Mar-16 21:17pm
Comments
Herman<T>.Instance 1-Mar-16 3:30am    
Have you tried EPPLUS?
Indukanth 1-Mar-16 3:48am    
Hi sir,
actually my entire project is working with this Spire.XLS, now i got a new requirement for find the formula cells.
thats why im using this.
Herman<T>.Instance 1-Mar-16 4:12am    
Can you detect the Range used in the sheet?
Indukanth 1-Mar-16 5:13am    
i tried the below snippet but didn't get any results..

var temp= sheet.Range["A1"].Formula;
if (sheet.Range[1, 1].FormulaBoolValue)
{
MessageBox.Show("test");
}
im not too familiar range.
how can go through this?
Herman<T>.Instance 1-Mar-16 5:15am    
A Range is an area that contains multiple Columns and or ROWS. So try to detect how c# can select that Range (A1 is only 1 cell) like A1:Z25.
Then iterate over Rows and Columns

Try this code snippets:
C#
foreach (CellRange cr in sheet.Range["A1:C4"].Cells)
{
    if(cr.HasFormula)
    {
       //..
    }
}
 
Share this answer
 
A statement sheet.Rows[0]["A1"].Formula; returns variant (type of string). If if starts with "=", this means that cell contains formula.
See: Range.Formula Property (Excel)[^]
 
Share this answer
 
Comments
Indukanth 1-Mar-16 23:06pm    
Hi Maciej Los im using Spire.XLS.
I think i tried this code. but it doesn't return any result.
Maciej Los 2-Mar-16 12:16pm    
string s = sheet.Rows[0]["A1"].Formula; if(s.StartsWith("=")) {Console.WriteLine("Contains formula!");}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900