WELCOME >>
Home services products support
Thursday, September 02, 2010 ..:: Blogs » Brian Swanson ::.. Register  Login
Sep 16

Written by: Brian Swanson
9/16/2009 10:00 AM 

I haven’t been blogging much lately, as I’m working full-time on TotalRM trying to get it to Beta very soon.

One of the things I’ve had to do for one of the companies that is using TotalRM internally on a limited basis, is importing data from an Excel spreadsheet.   As a result, I had need to parse a column number into an Excel column (column 1 is ‘A’, column 27 is ‘AA’, etc).  I searched the internet and found a solution which seemed to work perfectly until I ran into a spreadsheet that went beyond Excel column AY (column number 52).  Below is my updated function for creating the Excel Column from the column number being passed in:

 

   1:      Public Shared Function GetExcelColumn(ByVal ColumnNum As Integer) As String
   2:          Dim Result As String = String.Empty
   3:   
   4:          Dim Primary As Integer
   5:          Dim Secondary As Integer
   6:   
   7:          Primary = Int((ColumnNum - 1) / 26)
   8:          Secondary = ColumnNum - (Primary * 26)
   9:          
  10:          If Primary > 0 Then
  11:              Result = Chr(Primary + 64)
  12:          End If
  13:   
  14:          If Secondary > 0 Then
  15:              Result = Result + Chr(Secondary + 64)
  16:          End If
  17:   
  18:          Return Result
  19:      End Function

 

Hopefully this will be helpful to some other .Net (especially VB.Net) developer out there attempting to read data from an Excel spreadsheet.

Tags:

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 









Copyright 2008 by Purple Ant LLC   Terms Of Use  Privacy Statement