例如获取excel表头的函数,当列数超过26之后,列表头变为:AA,AB,AC.....,那么该如何获取呢?
eg:“A”+"A"="AA"
//自己写的获取单元头的函数 col:列数,row:行数 strName:表格名
void GetCellName(int nRow, int nCol, CString &strName)
{
int nSeed = nCol;//列数
CString strRow;
//比如nCol = 27
int numberOfCol = nCol / 27;//numberOfCol =1
std::string cellName;
if (numberOfCol!=0)
{
cellName = 'A' + numberOfCol-1;//cellName=A
nCol = nCol % 27+1;//nCol=1
}
cellName += 'A' + nCol - 1;//cellName = AA,为啥这样相加就可以组成AA ?因为 字符与字符相加是连接
//cellName.append('A' + nCol - 1);//与上面一句完全等价 报错的原因是('A' + nCol - 1)是一个字符不是字符串
strName.Format(_T("%s"), cellName.c_str());
strRow.Format(_T("%d "), nRow);
strName = strName + strRow;
}
本文介绍了一种用于生成Excel表格中超过26列后的特殊列头名称(如AA, AB等)的算法实现。该算法通过计算列数来确定如何组合字母以形成正确的列头标识符。
617

被折叠的 条评论
为什么被折叠?



