New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for exporting a tables with TBLFMs to ODS spreadsheet #197
Comments
Add support for exporting a tables with TBLFMs to ODS spreadsheet. See #197.
Cc @ouboub Just wanted to let you know that exporting of simple Table with TBLFMs to ODS is feasible. You will see commits on this issue. You can ignore the commits until you hear from me. Once the feature is complete I will share my Unit Test files. |
Add support for exporting a tables with TBLFMs to ODS spreadsheet. See #197.
…DS spreadsheet Initial cut for #197.
I am able to successfully convert the 2 tables you attached. Let me know if you face any issues. Instructions
Input
|
Instruction are there at #197 (comment) Unit test files, with input and output |
An
Show me the CLI that does org -> csv -> scalc -> csv -> org. I want to specifically see if you are setting any of the I think it will be useful to add a command to import an |
I attach a zip file that ontains a README file, an example org file and various results I obtain when I export it to ods following different strategies |
Making a note for future use. (defun my-toggle-org-date-format ()
"This function allows use English (US) or German or Spanish date format."
(interactive)
(with-output-to-temp-buffer "local-set-buffer"
(princ "List of functions\n")
(princ "1: my-set-time-stamp-english \n")
(princ "2: my-set-time-stamp-german \n")
(princ "3: my-set-time-stamp-spanish \n"))
(let ((ch (string-to-char (read-string "Which choice: 1: 2: 3: "))))
(call-interactively (cond ((eql ch ?2) #'my-set-time-stamp-german)
(t (error 'args-out-of-range '(1 2 3 ch))))))
(kill-buffer "local-set-buffer"))
(defun my-set-time-stamp-german ()
"Set the local environment so that German dates are inserted."
(interactive)
(set-language-environment "German")
(set-locale-environment "de_DE.UTF-8")
(message "Language setting is German"))
(defun org-table-export-to-spreadsheet (arg)
"Export org table to varios first to cvs and then via LO/OO
to various spreadsheet format, the most common are `ods', `xls' and
`xlsx'."
(interactive "sFormat: ")
(let* ((source-file (file-name-sans-extension (buffer-file-name (current-buffer))))
(csv-file (concat source-file ".csv")))
(org-table-export csv-file "my-tbl-to-csv")
(org-odt-convert csv-file arg)))
(defun my-tbl-to-csv (table params)
(orgtbl-to-csv table
(org-combine-plists '(:fmt my-format-timestamps) params)))
(defun my-format-timestamps (cell)
(org-quote-csv-field
(replace-regexp-in-string
org-ts-regexp-both
(lambda (m)
(format-time-string
(let ((hours? (string-match-p "[0-9]+:[0-9]+" m)))
(funcall (if hours? #'cdr #'car) org-time-stamp-custom-formats))
(apply #'encode-time (save-match-data (org-parse-time-string m)))))
cell)))
(setq org-odt-convert-process "gnumeric")
(setq org-odt-convert-processes '(("gnumeric" "/usr/bin/ssconvert %i %o")))
Note how the decimal separator changes from Look at |
From
|
Based on From Date acceptance patterns Specifies the date acceptance patterns for the current locale. Calc spreadsheet and Writer table cell input needs to match locale dependent date acceptance patterns before it is recognised as a valid date. If you type numbers and characters that correspond to the defined date acceptance patterns in a table cell, and then move the cursor outside of the cell, LibreOffice will automatically recognise and convert the input to a date, and format it according to the locale setting. The initial pattern(s) in Date acceptance patterns are determined by the locale (set in Locale setting), but you can modify these default patterns, and add more patterns. Use ; to separate each pattern. Patterns can be composed according to the following rules:
Examples of valid patterns are: D,Y ; Y-M ; M.D.Y ; D-M/Y ; M.D. If you change the Locale setting, the date acceptance pattern will be reset to the new locale default, and any user-defined modifications or additions will be lost. In addition to the explicit patterns defined in the edit box, input matching the Y-M-D pattern is implicitly recognised and converted automatically to a date. Input that starts from 1 to 31 is not interpreted with this implicit Y-M-D pattern. Since LibreOffice 3.5, this input is formatted as YYYY-MM-DD (ISO 8601). |
Some more notes ... I have looked at your
Think of We shouldn't let optics fool what is underneath in the core. |
There is some crucial piece missing here. Do you make For the purpose of inputtting to (defun replace-org-ts-with-locale-ts-in-string (string &optional locale)
(let ((local-env (or locale current-locale-environment)))
(with-locale-environment locale
(org-quote-csv-field
(replace-regexp-in-string
org-ts-regexp-both
(lambda (time-string)
(format-time-string
(let ((hours? (string-match-p "[0-9]+:[0-9]+" time-string)))
(funcall (if hours? #'cdr #'car) '("%x" . "%X")))
(apply #'encode-time (save-match-data (org-parse-time-string time-string)))))
string)))))
|
But there doesn't seem to be a way to convert an ISO date to LANG specific date. (The above example uses text based export.) The story is the same for File an enhacement report with |
There is another enhancement request you may want to file for Note that it changes the What you need from
|
I will roll out my spreadsheet exporter. It won't use What surprises me about your setup--atleast the parts you have shared with me--it appears to be incomplete. I have already pointed issues with the I can articulate what you want in technical terms ... But I don't want to overwhelm you. Take whatever works for you. |
Another point, since you are working on that exporter there is another structure (still no if involved) that would be nice to have
if you could implement that, it would be great, if not I can do this manually without much problem, the code in ods
sorry to bother you again |
… On Thu, 21 Jul, 2022, 21:29 Uwe Brauer, ***@***.***> wrote:
Another point, since you are working on that exporter there is another
structure (still no if involved) that would be nice to have
generate a numbered row, starting from an arbitrary number, here is the
org code with the tables.
| | Stuff |
|---+-------|
| 1 | test |
| 2 | new |
| 3 | this |
| 4 | hello |
#+TBLFM: $1=@#-1
| | Table2 |
|-----+--------|
| 101 | test |
| 102 | new |
| 103 | this |
| 104 | hello |
#+TBLFM: $1=@#-1+100
if you could implement that, it would be great, if not I can do this
manually without much problem, the code in ods
would be
,Table 2
101,test
=A2+1,new
=A3+1,this
=A4+1,hello
sorry to bother you again
—
Reply to this email directly, view it on GitHub
<#197 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEXTBKD7E4IQKUZIPNU45BLVVFXWJANCNFSM53X2VR3A>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
I was checking if Emacs provides locale dependent NUMERIC formatting. It doesen't There are some recent LOCALE specific threads, in the context of CSV Probably there are others ... Probably easier to spot these threads in Gnus / Gmane / Gwene, rather than on a web interface. |
…viour * lisp/ox-ods.el (org-ods-cell-mapper): Set this to `org-ods-replace-org-ts-with-locale-ts-in-string'. So, that brackets around timestamps are stripped, and the timestamp is converted in to locale specific string. If this is not what you want, set this to `nil'. (org-ods-calc-f->ods-f-alist): Add entries for `vmean', `$#', and `@#'. (org-ods-convert, org-ods-translate): If you bind `TABLE_CONVERTER_ENV' as below, `#+BIND: TABLE_CONVERTER_ENV (("LANG" "de_DE.UTF-8"))', then the `org-odt-convert' and `org-ods-translate' behave in locale-specific way. (org-ods--with-environment): New macro. * lisp/ox-odt.el (org-odt-convert-processes): Add Gnumeric/ssconvert (org-odt-do-convert): Add `%l' format-spec for passing on a LANG environment variable. More fixes for #197.
* testing/examples/odt/tblfms-to-ods.org: Some test cases for previous commit. There is some problem with 'colnos' table. That is, `$#'. See #197.
You can look at the commit message for other changes. |
A comment given
then
that is not good, better would be
any change to achive that? thanks |
…le): New * lisp/ox-ods.el (org-ods-table->table-info): New. Core functiont that parses a table in to its component parts for use with translating TBLFMs in to ODS formula. (org-ods-insert-dblock, org-dblock-write:ods-table) (org-ods-do-write-ods-table): New. * testing/examples/odt/tblfms-to-ods.org: Add `ods-table' view for all formula tables. This way, a simple `C-c C-c' can refresh the view. Remove dependency on `dash`. Introduce a new dynamic block named `ods-table'. This table captures the "ODS formula" view of an `Org' table. In order to create a `ods-table' view for an `Org' table, the `Org' table needs to have a unique `#+NAME: ...' attribute. A `ods-table' dblock can be created like any other `Org' dynamic block, by doing `C-x C-x x' and following the prompts. See `testing/examples/odt/tblfms-to-ods.org' for more details. More fixes for #197.
I have added a See the committed changes to get started.
In the above table
|
* lisp/ox-ods.el: Handle the case where LHS is a range of cells * testing/examples/odt/tblfms-to-ods.org: Updated to reflect the current state More fixes for #197.
thank you for these instructions. I have already copied them to my README file. I will try to nail that problem down and if I find anything useful I report back. |
* lisp/ox-ods.el: Handle table with special rows; a first cut. * testing/examples/odt/tblfms-to-ods.org: Updated to reflect the current state. Also remove lots of cruft. More fixes for #197.
Some more things for your
This is how you unit test the changes
(require 'org)
(defun org-clear-all-dblocks ()
"Clear all dynamic blocks in the buffer."
(interactive)
(when (derived-mode-p 'org-mode)
(org-map-dblocks 'org-clear-dblock)))
(defun org-clear-dblock ()
"Clear the dynamic block at point."
(interactive)
(save-excursion
(let* ((win (selected-window))
(pos (point))
(line (org-current-line))
(params))
(org-prepare-dblock))))
(define-key org-mode-map (kbd "C-c C-x C-SPC") #'org-clear-all-dblocks)
|
I have closed this bug.
Sample spreadsheets produced by this exporter. tblfms-to-ods#generic1.ods Put your cursor on a table--an You will get a spreasheet that is natively produced by this exporter.
|
thanks very much! |
I pulled, compiled and tested, a couple of remarks
|
Empty string is a corner case. The This is something that I can consider for a distant future, not now |
…ble NAME * lisp/ox-ods.el (org-ods-export-to-ods): Pass in the `:uniquifier' to `org-odt-export-to-odt-backend' option to `org-odt-export-to-odt-backend'. * lisp/ox-odt.el (org-odt-export-to-odt-backend): Honor the `:uniquifier' option. See #197.
* lisp/ox-ods.el (org-ods-convert-process): Converter name to use for converting ODS files to other related formats. Defaults to "LibreOffice". (org-ods-export-to-ods): Let bind `org-odt-convert-process' to `org-ods-convert-process'. This changes enables having different converters for ODT and ODS documents. For example, one may want `soffice'/`LibreOffice' as a converter for `odt' documents, but want `ssconvert'/`Gnumeric' as a converter for ODS documents. See #197.
* lisp/ox-odt.el (org-odt-do-convert): Shell quote output file name. See #197.
* lisp/ox-ods.el (org-ods-export-to-ods): Don't override the `ext-plist' passed by the user. See #197.
…extra emphasis markers in spreadsheet cells * lisp/ox-ods.el (org-ods-automatic-styles): New user option. (org-ods-preferred-output-format): Fix custom properties. (org-ods--translate-tblfms-to-ods-formulae): (ods): Initialize `:odt-automatic-styles' to `org-ods-automatic-styles' * etc/styles/ods/content.xml: Copy over all styles from within `<office:styles>...</office:styles>' of `OrgOdtStyles.xml' to `<office:automatic-styles>...</office:automatic-styles>'. * testing/examples/odt/tblfms-to-ods.org: Add a text table that uses `org' and `extra' emphasis markers. Changes in order to support regular `Org' emphasis markers and extra emphasis markers[1] for styling cell text. [1] https://github.com/QiangF/org-extra-emphasis See #197.
… r`ods' backend * org-extra-emphasis.el (org-extra-emphasis-backends): Add `ods' backend. (org-extra-emphasis-update): Update `org-ods-automatic-styles'. (org-extra-emphasis-formatter): Add support for `ods' backend. Add support for extra emphasis markers in ODS export. See kjambunathan/org-mode-ox-odt#197.
I have added support for extra emphasis markers in My experimentation suggests that
Regarding the background color, I need to review the styles or talk to the LibreOffice team. Nevertheless ... this is a useful improvement. To get this (modulo the column widths) do this
|
I have used spreadsheet in the past for creating bursary application for my sister and nephew. The tables were regular spreadsheet columns--figures from pay check, income tax forms etc--and also text fields which adds some notes to the figures. So, wrapping of cell text is something I have needed in the past. If you have suggestions or preferences I will consider it. The suggestion shouldn't be for your specific case, but for a hypothetical user. Ultimately, I will add support for exporting all tables in an I never dreamed that I would be adding a `ods' backend. A simple nudge was all that is needed to get this feature out. It was a marathon hacking session, and I haven't done this in quite some time. So, thanks. |
thanks! I usually pull run make clean and then make again I will try this out later |
Thanks very much.
|
>> "JK" == Jambunathan K ***@***.***> writes:
> | | Stuff |
> |---+-------|
> | 1 | test |
> | 2 | new |
> | 3 | this |
> | 4 | hello |
> #+TBLFM: $1=@#-1
Your example works with the latest commit. (Lightly tested)
Thanks I run some tests:
```
| Number | Topic |
|--------+-------|
| 1 | test |
| 2 | new |
| 3 | this |
| 4 | hello |
| 5 | this |
#+TBLFM: $1=@#-1
```
Is translated into
```
| Number | Topic |
|----------+-------|
| =ROW()-1 | test |
| =ROW()-1 | new |
| =ROW()-1 | this |
| =ROW()-1 | hello |
| =ROW()-1 | this |
```
Which is correct, thanks!
…--
I strongly condemn Putin's war of aggression against the Ukraine.
I support to deliver weapons to Ukraine's military.
I support the ban of Russia from SWIFT.
I support the EU membership of the Ukraine.
|
Publish elpa/ox-odt-9.6.524.tar This release includes the following major features - Support for exporting tables to OpenDocument Spreadsheet. You can now export a table to ODS file with `org-ods-export-to-ods' bound to `C-c C-e o s' or `C-c C-e o S'. - Fixes kjambunathan/org-mode-ox-odt/issues/197. - lisp/odt.el: New library for manipulating DOM of ODF files - See kjambunathan/org-mode-ox-odt/issues/220. - Support for indices (WIP) This release includes the follow minor features - New command `org-odt-insert-style-name-or-style-definition-from-file' - Fixes kjambunathan/org-mode-ox-odt/issues/224 - Cusomize a page header and footer through `header' and `footer' special blocks - Fixes kjambunathan/org-mode-ox-odt/issues/221. See also kjambunathan/org-mode-ox-odt/issues/182 and kjambunathan/org-mode-ox-odt/issues/180. - Add `fodt' to org-odt-convert-capabilities - Partial fix for kjambunathan/org-mode-ox-odt/issues/217. - Teach `dired-do-compress' how to uncompress all OpenDocument files - Produce Landscape and other documents with ease - Fixes issue kjambunathan/org-mode-ox-odt/issues/198. - Minor enhancements to produce Org tables that uses LibreOffice Table Templates (like `Academic', for example). - Partial fix for kjambunathan/org-mode-ox-odt/issues/199. This release includes the follow major bug fixes - De-duplicate styles using DOM APIs - Fix kjambunathan/org-mode-ox-odt/issues/220 This corresponds to commit c5165a8e311d65d2571d19464587905a5a160385
Cc @ouboub
Thanks, I attach a zip file with a README file that explains the purpose of each file
HG-CVS-Formular.zip
See also #94
The text was updated successfully, but these errors were encountered: