KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
What is the fastest c# function that takes and int and returns a string containing a letter or letters for use in an Excel function? For example, 1 returns "A", 26 returns "Z", 27 returns "AA", etc. This is called tens of thousands of times and is taking 25% of the time needed to generate a large spreadsheet with many formulas. public string Letter(int intCol) { int intFirstLetter = ((intCol) / 676) + 64; int intSecondLetter = ((intCol % 676) / 26) + 64; int intThirdLetter = (intCol % 26) + 65; char FirstLetter = (intFirstLetter > 64) ? (char)intFirstLetter : ' '; char SecondLetter = (intSecondLetter > 64) ? (char)intSecondLetter : ' '; char ThirdLetter = (char)intThirdLetter; return string.Concat(FirstLetter, SecondLetter, ThirdLetter).Trim(); }
Tags (comma-separated)
Save Edits
Cancel