Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

Created Unassigned: get column name from index [9424]

$
0
0
To get the name of a column based on it's index, I added the following function to XlWorksheet. This will return
"A3" for columnindex=1 and rowindex=3 -> the columnindex is 1-based
public static string GetColumnAddress(int columnIndex, int rowIndex)
{
string columnName = string.Empty;
while (columnIndex > 0)
{
int remainder = (columnIndex - 1) % 26;
columnName = Convert.ToChar(65 + remainder) + columnName;
columnIndex = (columnIndex - remainder) / 26;
}
return columnName + rowIndex.ToString();
}

Viewing all articles
Browse latest Browse all 1877

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>