We help IT Professionals succeed at work.

Excel API - I know row # but how to convert 52 into AZ ?

bswiftly
bswiftly asked
on
298 Views
Last Modified: 2012-05-05
I am generating an excel spreadsheet and there will be an unknown amount of columns created (decided at runtime).  I know that the last column index could be say... 63.

But I need to do a formula for the row not all, just from column 3-62.  but i can't do

formula =SUM(3:3,3:63), i have to do this:
formula =SUM(C3,BK3)  etc.


How can i convert 63 into BK (if thats what it is?) without creating a HUGE select statement ?
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks again Bob!
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
Yeah, Brett, I can answer the easy ones. ;)

Bob

Author

Commented:
i'm doing this in C# - maybe here's an easier question.. i tried to find the equivalent of Chr(3) in c# last week and couldn't find it.. do you know what it is ?

Author

Commented:
the value of a fresh brain in the morning.  duh

convert.tochar(i);

thanks

Author

Commented:
oh man, I am jumping the gun too much this morning.

that code didn't work :(

try passing it a value of 52, and 53.  

Author

Commented:
first col is index 1, not zero :)

public static string GetAlphaColName(int index)
{
      index -= 1;
      int first = (index) / 26;
      int second = index % 26;
      if (first > 0)
      {
            return Convert.ToChar(64 + first).ToString() + Convert.ToChar(65 + second).ToString();
      }
      else
      {
            return  Convert.ToChar(65 + second).ToString();
      }
}
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.