Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 482835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:08:10+00:00 2026-05-13T01:08:10+00:00

I need to know column name of a spread sheet with a given starting

  • 0

I need to know column name of a spread sheet with a given starting colum upto n number of columns
let say starting column is “AB”, I want to know the column (label) after 99 columns.

For those who need Ralph answer in T-SQL flavor

Create FUNCTION fsExcelValueToColum(@value int) returns varchar(3) as
begin
DECLARE @DIGIT INT,@RV VARCHAR(3);set @rv=''
IF @VALUE=0 RETURN @rv
WHILE @VALUE > 0
    BEGIN
        SET @DIGIT = @VALUE % 26 
        IF @DIGIT = 0 
            BEGIN
                set @RV=@RV+'Z'
                set @RV=@RV+dbo.fsExcelValueToColum(@value /26 -1)
                return @rv
            END
            set @rv=@rv+char(@digit+64)
            set @value=(@value-@digit) /26
    END
    return @rv
end
USE [ecs]
GO
/****** Object:  UserDefinedFunction [dbo].[fnExcelColumnToValue]    Script Date: 12/06/2009 10:33:37 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER function [dbo].[fnExcelColumnToValue](@Column varchar(3)) returns int as
Begin
--declare @column varchar(10); select @column = 'AC'
declare @value int, @pow int,@i int,@n int
select @pow=1,@VALUE=0,@I=LEN(@COLUMN)
SET @I=LEN(@COLUMN)
WHILE @I >= 1
    BEGIN
        SET @VALUE=@VALUE+@POW*((ASCII(SUBSTRING(UPPER(@COLUMN),@I,1)) - 65) +1)
        SET @POW=@POW *26
        SET @I=@I-1
    END
    return @value
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T01:08:10+00:00Added an answer on May 13, 2026 at 1:08 am

    Think of the characters A, B, … , Z as representing the values 1, 2, … 26 (you can’t quite think of this as being base-26 because there is no character representing 0 nor can there be as we don’t want, for example, AA to mean 0). So we have to engage in some trickery to deal with this:

    static int ColumnToValue(string column) {
        int value = 0;
        int pow = 1;
        for (int i = column.Length - 1; i >= 0; i--) {
            value += pow * (column[i] - 'A' + 1);
            pow *= 26;
        }
        return value;
    }
    
    static string ValueToColumn(int value) {
        if (value == 0) {
            return string.Empty;
        }
        StringBuilder sb = new StringBuilder();
        while (value > 0) {
            int digit = value % 26;
            if (digit == 0) {
                sb.Insert(0, 'Z');
                return sb.Insert(0, ValueToColumn(value / 26 - 1)).ToString();
            }
            sb.Insert(0,(char)(digit + 'A' - 1));
            value = (value - digit) / 26;
        }
        return sb.ToString();
    }
    

    So that

    Console.WriteLine(ValueToColumn(ColumnToValue("AB") + 99));
    

    outputs DW and

    Console.WriteLine(ValueToColumn(ColumnToValue("AB") - 2));
    

    outputs Z. Obviously you can wrap this all up in a nice class and make it fluent or what have you.

    Explanation: Think, for example, of the value 702 and a usual base-26 notation where there is a digit representing 0 (I will use the notation _ to represent this magical digit so that we don’t get confused between the value 0 and the digit 0). Let’s try to convert 702 (decimal) to base-26. The usual algorithm is compute 702 % 26 which is 0 so that we would have the last digit as being _. Then we would divide by 26 to obtain 27. We would note that 27 % 26 is 1 so that the penultimate digit is A. Then we would divide by 26 to obtain 1, compute 1 % 26 to obtain 1 and report that the most-significant digit is A. We would return AA_ as the string representing 702 in base-26 with digits (_ = 0, A = 1, … Z = 26) (check: 1 * 26^2 + 1 * 26^1 + 0 * 26 = 702). For our purposes, this is wrong. We wanted to get back the string ZZ (because we have 26 digits A, B, C, … Z representing 1, 2, … 26 (remember, no digit representing the value 0!) so that ZZ = 26 * 26^1 + 26 * 26^0 = 702). It turns out in our system that numbers congruent to 0 modulo 26 should have least-significant digit Z. So this suggests that our algorithm should be check and see if value is congruent to 0 modulo 26. If it is, prepend a Z and then prepend the string representing the value value / 26 - 1. This is the algorithm that you see above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to know about Epoll On linux System. Could you recommend manual or
I need to know how the performance of different XML tools (parsers, validators, XPath
I need to know how much space occupies all the databases inside an SQL
I need to know how to turn on Code Coverage when running TFS builds
I need to know when the memory will be allocated for a particular program.
I need to know, from within Powershell, if the current drive is a mapped
I need to know how I get the stream of the headers and footers
I need to know what internet connection is available when my application is running.
I need to know when the user finishes editing a cell in an NSTableView.
I need to know what is code compiled unit in .net. It s located

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.