C# Facing issue to extract excel cell address from formula using RegEx

  • Thread starter Thread starter Sudip_inn
  • Start date Start date
S

Sudip_inn

Guest
I have application which read data from excel file including formula using EPPlus. my routine extract cell address from formula.

few sample formula which my application can still parse using RegEx.


a) (W2/R2)-1
b) W23-U23


But Now a formula occur bit long which my regex could not parse. formula looks like (U2+W2)/2*1000/W25

This is my code which parse formula and iterate in cell address

string regex = @"\$?[A-Z]{1,3}\$?[0-9]{1,7}";
string strDefaultCalculations="(U2+W2)/2*1000/W25";

List<string> lstAddress = Regex.Matches(strDefaultCalculations, regex).Cast<Match>().Select(m => m.Value).ToList();

foreach (var data in lstAddress)
{

}




Please some one suggest any changed RegEx as a result it can extract all cell address from this formula (U2+W2)/2*1000/W25. cell address would be U2, W2, W25.

also changed regex should be parse my others formula too means these formula below which are being parsed properly.


a) (W2/R2)-1
b) W23-U23


Please some one help me. i stuck very badly for my RegEx. thanks

Continue reading...
 
Back
Top