计算EXCEL列名代号的程序

None.gif // 计算结果格式:
None.gif        
// 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,
None.gif        
// AA,AB,AC,AD,AE,AF,AG,AH,AI,AJ,AK,AL,AM,AN,AO,AP,AQ,AR,AS,AT,AU,AV,AW,AX,AY,AZ,
None.gif        
// BA,BB,BC,BD,BE,BF,BG,BH,BI,BJ,BK,BLdot.gifdot.gif
None.gif
         private   void  buttonXP1_Click( object  sender, System.EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
string s="A";
InBlock.gif            
for(int i=0;i<2700;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.richTextBox1.Text +=s+",";
InBlock.gif                s
=InreasingData(s);
InBlock.gif                 
ExpandedSubBlockEnd.gif            }

InBlock.gif          MessageBox.Show(s)  ;
InBlock.gif
ExpandedBlockEnd.gif        }

None.gif        
private   string  InreasingData( string  strTemp)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
int i=strTemp.Length ;
InBlock.gif            
char[] ca=new char[i];
InBlock.gif            ca
=strTemp.ToCharArray();  
InBlock.gif            
bool bCarryFlag=true;
InBlock.gif            
int w=i-1;
InBlock.gif        
InBlock.gif            
int AddResult=(int)ca[w];
InBlock.gif            AddResult
+=1;
InBlock.gif
InBlock.gif        
InBlock.gif            
while((bCarryFlag)&&(w>=0))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
InBlock.gif                
if(AddResult>90)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    ca[w]
='A';    
InBlock.gif                    
InBlock.gif                    
InBlock.gif                    
if(w>0)
InBlock.gif                    AddResult
=(char)((int)ca[w-1]+1);
InBlock.gif
InBlock.gif                
InBlock.gif                
InBlock.gif                    bCarryFlag
=true;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    ca[w]
=(char)((int)ca[w] +1);
InBlock.gif                    bCarryFlag
=false;
ExpandedSubBlockEnd.gif                }

InBlock.gif                w
--;
InBlock.gif                    
ExpandedSubBlockEnd.gif            }

InBlock.gif            strTemp
="";
InBlock.gif            
for(int j=0;j<i;j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                strTemp
+=ca[j].ToString(); 
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if((w<0)&&(bCarryFlag))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                strTemp
="A"+strTemp;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
InBlock.gif            
return strTemp;
ExpandedBlockEnd.gif        }
ExpandedBlockStart.gif ContractedBlock.gif Private   Sub ButtonXP1_Click() Sub ButtonXP1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonXP1.Click
InBlock.gif        
Dim i As Int16 = 0
InBlock.gif        
Dim s As String = "A"
InBlock.gif        
Me.RichTextBox1.Text &= s & "',"
InBlock.gif        
For i = 0 To 1000
InBlock.gif            s 
= IncreasingData(s)
InBlock.gif            
Me.RichTextBox1.Text &= s & "',"
InBlock.gif        
Next
InBlock.gif
InBlock.gif
ExpandedBlockEnd.gif    
End Sub

None.gif
ExpandedBlockStart.gifContractedBlock.gif    
Private   Function IncreasingData() Function IncreasingData(ByVal strTemp As StringAs String
InBlock.gif        
Dim i As Integer = strTemp.Length
InBlock.gif        
Dim ca(i) As Char
InBlock.gif        ca 
= strTemp.ToCharArray()
InBlock.gif        
Dim bCarryFlag As Boolean = True
InBlock.gif        
Dim w As Integer = (i - 1)
InBlock.gif        
Dim AddResult As Integer = Microsoft.VisualBasic.AscW(ca(w))
InBlock.gif        AddResult 
+= 1
InBlock.gif        
While ((bCarryFlag) And (w >= 0))
InBlock.gif            
If (AddResult > 90Then
InBlock.gif                ca(w) 
= "A"
InBlock.gif                
If (w > 0Then
InBlock.gif                    AddResult 
= Microsoft.VisualBasic.AscW(ca(w - 1)) + 1
InBlock.gif                    bCarryFlag 
= True
InBlock.gif                
End If
InBlock.gif            
Else
InBlock.gif                ca(w) 
= Microsoft.VisualBasic.ChrW(Microsoft.VisualBasic.AscW(ca(w)) + 1)
InBlock.gif                bCarryFlag 
= False
InBlock.gif            
End If
InBlock.gif            w 
= w - 1
InBlock.gif        
End While
InBlock.gif        strTemp 
= ""
InBlock.gif        
Dim j As Integer = 0
InBlock.gif        
For j = 0 To i - 1
InBlock.gif            strTemp 
&= ca(j).ToString()
InBlock.gif        
Next
InBlock.gif        
If ((w < 0And (bCarryFlag)) Then
InBlock.gif            strTemp 
= "A" & strTemp
InBlock.gif        
End If
InBlock.gif        
Return strTemp
ExpandedBlockEnd.gif    
End Function
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值