Excel Sheet Column Title

Source: Internet
Author: User

This article is in the study summary, welcome reprint but please specify Source:http://blog.csdn.net/pistolove/article/details/42554641


Given a positive integer, return its corresponding column title as appear in an Excel sheet.

For example:

    1, A    2, B    3, C    ...    AA, Z        

Ideas:

(1) Test instructions the string corresponding to the column in Excel, given any integer.

(2) The essence of this problem is to examine the application of "26-system". Because the problem is relatively simple, here is not verbose, see the code below.

(3) Hope this article is helpful to you.


The algorithm code is implemented as follows:

public static String converttotitle (int num) {if (num < 1) {return "";} else {String temp = ""; StringBuffer buffer = new StringBuffer (), while (num > 0) {num--;char c = (char) (num% + ' A '), temp + = C;num/= 26;} for (int i = Temp.length ()-1; I >= 0; i--) {Buffer.append (Temp.charat (i));} return buffer.tostring ();}}



Excel Sheet Column Title

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.