reddit / emacs

How to retain leading zeros in a cell when processing org-mode table with elisp?

whudwl · 2022-12-15 01:47
Hi Guys, I was wondering if anyone can help me with the issue below. I'm trying to process org-mode table using elisp as shown below. It seems that org would think my data is of INT type and lose the leading zeros, but in fact it is of TEXT type. How do I make org treat my data as TEXT instead of number? I cannot simply add leading zeros after processing, as the number of zeros is uncertain. ​ `#+name:test_table` `|001024|` ​ `#+begin_src elisp :var data=test_table` `(-map` `(lambda (row)` `(format "%s" (car row)))` `data)` `#+end_src` ​ `#+RESULTS:` `| 1024 |`
stormrider-io · 2022-12-15 02:03
I think you can format the cell in a formula with %2.0f.
scbagley · 2022-12-15 02:41
Put the cell contents in quotes: #+name:test_table |"001024"| The function `org-babel-read` evaluates strings by calling `read` on them, thereby losing any leading zeros.
whudwl · 2022-12-16 01:54
Thanks. It seems this is the correct way to do it.