Skip to content

Commit

Permalink
feat(text): Add CHAR function.
Browse files Browse the repository at this point in the history
  • Loading branch information
vinci1it2000 committed May 30, 2024
1 parent bb6b935 commit 13d5c7d
Show file tree
Hide file tree
Showing 3 changed files with 243 additions and 0 deletions.
241 changes: 241 additions & 0 deletions formulas/functions/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,247 @@

FUNCTIONS = {}

codes = {
9: "\t",
10: "\n",
32: " ",
33: "!",
34: '"',
35: "#",
36: "$",
37: "%",
38: "&",
39: "'",
40: "(",
41: ")",
42: "*",
43: "+",
44: ",",
45: "-",
46: ".",
47: "/",
48: "0",
49: "1",
50: "2",
51: "3",
52: "4",
53: "5",
54: "6",
55: "7",
56: "8",
57: "9",
58: ":",
59: ";",
60: "<",
61: "=",
62: ">",
63: "?",
64: "@",
65: "A",
66: "B",
67: "C",
68: "D",
69: "E",
70: "F",
71: "G",
72: "H",
73: "I",
74: "J",
75: "K",
76: "L",
77: "M",
78: "N",
79: "O",
80: "P",
81: "Q",
82: "R",
83: "S",
84: "T",
85: "U",
86: "V",
87: "W",
88: "X",
89: "Y",
90: "Z",
91: "[",
92: "\\",
93: "]",
94: "^",
95: "_",
96: "`",
97: "a",
98: "b",
99: "c",
100: "d",
101: "e",
102: "f",
103: "g",
104: "h",
105: "i",
106: "j",
107: "k",
108: "l",
109: "m",
110: "n",
111: "o",
112: "p",
113: "q",
114: "r",
115: "s",
116: "t",
117: "u",
118: "v",
119: "w",
120: "x",
121: "y",
122: "z",
123: "{",
124: "|",
125: "}",
126: "~",
127: "",
128: "Ä",
129: "Å",
130: "Ç",
131: "É",
132: "Ñ",
133: "Ö",
134: "Ü",
135: "á",
136: "à",
137: "â",
138: "ä",
139: "ã",
140: "å",
141: "ç",
142: "é",
143: "è",
144: "ê",
145: "ë",
146: "í",
147: "ì",
148: "î",
149: "ï",
150: "ñ",
151: "ó",
152: "ò",
153: "ô",
154: "ö",
155: "õ",
156: "ú",
157: "ù",
158: "û",
159: "ü",
160: "†",
161: "°",
162: "¢",
163: "£",
164: "§",
165: "•",
166: "¶",
167: "ß",
168: "®",
169: "©",
170: "™",
171: "´",
172: "¨",
173: "≠",
174: "Æ",
175: "Ø",
176: "∞",
177: "±",
178: "≤",
179: "≥",
180: "¥",
181: "µ",
182: "∂",
183: "∑",
184: "∏",
185: "π",
186: "∫",
187: "ª",
188: "º",
189: "Ω",
190: "æ",
191: "ø",
192: "¿",
193: "¡",
194: "¬",
195: "√",
196: "ƒ",
197: "≈",
198: "∆",
199: "«",
200: "»",
201: "…",
202: " ",
203: "À",
204: "Ã",
205: "Õ",
206: "Œ",
207: "œ",
208: "–",
209: "—",
210: "“",
211: "”",
212: "‘",
213: "’",
214: "÷",
215: "◊",
216: "ÿ",
217: "Ÿ",
218: "⁄",
219: "€",
220: "‹",
221: "›",
222: "fi",
223: "fl",
224: "‡",
225: "·",
226: "‚",
227: "„",
228: "‰",
229: "Â",
230: "Ê",
231: "Á",
232: "Ë",
233: "È",
234: "Í",
235: "Î",
236: "Ï",
237: "Ì",
238: "Ó",
239: "Ô",
240: "",
241: "Ò",
242: "Ú",
243: "Û",
244: "Ù",
245: "ı",
246: "ˆ",
247: "˜",
248: "¯",
249: "˘",
250: "˙",
251: "˚",
252: "¸",
253: "˝",
254: "˛",
255: "ˇ"
}


def xchar(number):
number = int(number)
if 0 < number <= 255:
if number in codes:
return codes[number]
return f'_x{hex(number)[2:].upper():0>4}_'
return Error.errors['#VALUE!']


FUNCTIONS['CHAR'] = wrap_ufunc(xchar)


def _str(text):
if isinstance(text, bool):
Expand Down
2 changes: 2 additions & 0 deletions test/test_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def inp_ranges(*rng):
@ddt.ddt
class TestCell(unittest.TestCase):
@ddt.idata([
('A1', '=CHAR(1)', {}, '<Ranges>(A1)=[[\'_x0001_\']]'),
('A1', '=CHAR(157)', {}, '<Ranges>(A1)=[[\'ù\']]'),
('A1', '=TEXT("a", "mm")', {}, '<Ranges>(A1)=[[\'a\']]'),
('A1', '=VALUE("26/08/1987 12:00")', {},
'<Ranges>(A1)=[[32015.5]]'),
Expand Down
Binary file modified test/test_files/test.xlsx
Binary file not shown.

0 comments on commit 13d5c7d

Please sign in to comment.