flextable icon indicating copy to clipboard operation
flextable copied to clipboard

Feature request: export as excel format

Open leeangling opened this issue 3 years ago • 8 comments

is it possible to export as excel format? sometimes, the table is too wide to fit into word document. if the table can be saved into excel format, we don't need to worry about the column width and also we can be flexible in review the data in the table.

leeangling avatar Aug 04 '22 11:08 leeangling

Just came here to check for this feature as well.

kotliary avatar Aug 04 '22 17:08 kotliary

This is a huge work and will not be available before a long time.

The data will be formatted: values are transformed into characters. I doubt we can reverse user-formats from R to Excel-formats, is it still wanted? For example, a column originally stored as numeric, will be stored in Excel as character; you will not be able to compute a mean on this column.

davidgohel avatar Aug 07 '22 13:08 davidgohel

I don’t think it’s necessary to transfer the format for excel. We just need a more flexible file to present the data. With excel file, we can easily handle really wide tables and use excel functions to review the data. It should be fine if we can’t do the computation in excel. If it’s really needed, user can manually edit the format in excel.

leeangling avatar Aug 08 '22 11:08 leeangling

For reference, I once wrote a proof of concept function to do just that. Convert a flextable into a openxlsx2 workbook. It's a bit dated, "slow" and does not feature all flextables, but still does the trick. https://github.com/JanMarvin/openxlsx2/discussions/445#discussioncomment-4488651

JanMarvin avatar May 19 '23 18:05 JanMarvin

sorry @JanMarvin. We appreciate your suggestion to implement that feature, and we do have some existing drafts, for some features we will need to discuss with you. However, the implementation you provided doesn't quite meet our requirements (you can try it yourself, for example, with as_flextable(tabular(...))). Additionally, we are aware that you have submitted pull requests for 'mschart', and we understand the need to review them. Unfortunately, time is scarce for us at the moment, and we are uncertain when we will have the availability to thoroughly review all of your nice work.

davidgohel avatar May 20 '23 08:05 davidgohel

Hi @davidgohel, exactly, the list of what my proof-of-concept function can't do is still relatively long (it's above in the linked post), but nevertheless many of the less complex tables can already be converted to native xlsx variants along with the entire table layout. I had written the linked function at the time to have another use case for openxlsx2. However, without using flextable myself, which is why I would have to rely on e.g. your input for a better implementation. Currently it is nothing more than a proof that converting flextable objects into native xlsx worksheets is possible. I only wrote because I was reminded of the issue here last night via a StackOverflow post.

And with mschart, I fully understand and have absolutely no rush. My pull request works for my use case.

JanMarvin avatar May 20 '23 09:05 JanMarvin

Here is my solution to this problem Package Link

It's my first run on this problem from a standalone package perspective and there is much work to be done. Still, better than nothing I guess.

Thanks to @JanMarvin for his inspirational work!

pteridin avatar Aug 21 '23 20:08 pteridin

@pteridin sorry for the very late answer. This looks excellent. I just had a quick try, it works very well.

davidgohel avatar Oct 19 '23 17:10 davidgohel