Logic to load the list with the series of excel columns (alphabetic) by giving the number of columns is required.
Later this list can be useful for creating data column on DataTable.
for Example, if you want to create 30 columns , list will be filled with
A
B
C
D
E
.
.
.
AA
AB
AC
AD
static void Alpha(ref List<string> col, List<string> alp,int num)
{
string temp = "";
int set = 0;
int j = 1;
for(int i=0 ;i<num;i++)
{
col.Add(temp + alp[j-1]);
if (j % alp.Count == 0)
{
temp = col[set];
set++;
j = 0;
}
j++;
}
}
static void Main(string[] args)
{
List<string> alp = new List<string>() { "A","B","C","D","E","F","G","H","I","J","K","L",
"M","N","O","P","Q","R","S","T","U","V","W","X",
"Y","Z"};
List<string> columns = new List<string>();
int numOfCols = 30;
Alpha(ref columns, alp, numOfCols);
}
No comments:
Post a Comment