From 511e87c163f4768eeb3a6e1880f7d02e771b51bc Mon Sep 17 00:00:00 2001
From: Nicolas Delaby <nicolas@nexedi.com>
Date: Wed, 19 Nov 2008 15:56:30 +0000
Subject: [PATCH] add function to convert int to letters

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24638 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Type/Utils.py    | 9 +++++++++
 product/ERP5Type/__init__.py | 3 ++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/product/ERP5Type/Utils.py b/product/ERP5Type/Utils.py
index 64f6818298..c7c62ba235 100644
--- a/product/ERP5Type/Utils.py
+++ b/product/ERP5Type/Utils.py
@@ -259,6 +259,15 @@ def getPath(object_or_path, **kw):
     return path.split('/')
   return path
 
+def int2letters(i):
+  """
+  Convert an integer to letters, to generate spreadsheet column id
+  A, B, C ..., Z, AA, AB, ..., AZ, BA, ..., ZZ, AAA ...
+  """
+  if i < 26:
+    return (chr(i + ord('A')))
+  d, m = divmod(i, 26)
+  return int2letter(d - 1) + int2letter(m)
 
 #####################################################
 # Globals initialization
diff --git a/product/ERP5Type/__init__.py b/product/ERP5Type/__init__.py
index 0884966ebe..9827c9c45c 100644
--- a/product/ERP5Type/__init__.py
+++ b/product/ERP5Type/__init__.py
@@ -107,7 +107,8 @@ from AccessControl.SecurityInfo import ModuleSecurityInfo
 allow_module('Products.ERP5Type.Cache')
 ModuleSecurityInfo('Products.ERP5Type.Utils').declarePublic(
     'sortValueList', 'convertToUpperCase', 'UpperCase',
-    'convertToMixedCase', 'cartesianProduct', 'sleep', 'getCommonTimeZoneList')
+    'convertToMixedCase', 'cartesianProduct', 'sleep', 'getCommonTimeZoneList',
+    'int2letters',)
 
 allow_module('Products.ERP5Type.Message')
 ModuleSecurityInfo('Products.ERP5Type.Message').declarePublic('translateString')
-- 
2.30.9