MCPcopy Create free account
hub / github.com/QtExcel/QXlsx / convertFromNumberToExcelColumn

Function convertFromNumberToExcelColumn

HelloAndroid/main.cpp:116–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114}
115
116std::string convertFromNumberToExcelColumn(int n)
117{
118 // main code from https://www.geeksforgeeks.org/find-excel-column-name-given-number/
119 // Function to print Excel column name for a given column number
120
121 std::string stdString;
122
123 char str[1000]; // To store result (Excel column name)
124 int i = 0; // To store current index in str which is result
125
126 while (n > 0) {
127 // Find remainder
128 int rem = n % 26;
129
130 // If remainder is 0, then a 'Z' must be there in output
131 if (rem == 0) {
132 str[i++] = 'Z';
133 n = (n / 26) - 1;
134 } else // If remainder is non-zero
135 {
136 str[i++] = (rem - 1) + 'A';
137 n = n / 26;
138 }
139 }
140 str[i] = '\0';
141
142 // Reverse the string and print result
143 std::reverse(str, str + strlen(str));
144
145 stdString = str;
146 return stdString;
147}

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected