数值转换为Excel列标的算法
http://www.itjxue.com 2015-07-17 00:54 来源:未知 点击次数:
本算法基于C++ Builder语法和类实现,功能描述如下:在进行OLE的Excel操作中,有时候需要使用Range的选择,此时需要提供坐标,坐标的列是由字符组成的,如:1-A,2-B,...,88-CJ,....,本算法即为将数字转换成对应的字符。
算法:
view plaincopy to clipboardprint?
AnsiString GetExcelRangeCode(int row, int col)
{
AnsiString asExcelCode = "" ;
while ( col ) {
asExcelCode = (AnsiString)(char)('A'+(col-1)%26) + asExcelCode ;
col = (col-1)/26 ;
}
return asExcelCode ;//+IntToStr(row) ;
}
AnsiString GetExcelRangeCode(int row, int col)
{
AnsiString asExcelCode = "" ;
while ( col ) {
asExcelCode = (AnsiString)(char)('A'+(col-1)%26) + asExcelCode ;
col = (col-1)/26 ;
}
return asExcelCode ;//+IntToStr(row) ;
}
/*该算法我尚未经过全面测试,目前仅确定1~208的对应关系正常*/