mwouts / itables

Pandas DataFrames as Interactive DataTables
https://mwouts.github.io/itables/
MIT License
710 stars 53 forks source link

Support for the cell range copy to excel #281

Open YongcaiHuang opened 1 month ago

YongcaiHuang commented 1 month ago

Great project!!

I am wondering is there any plan to support the cell range copy to excel! I believe this might be a compelling function!

mwouts commented 4 weeks ago

Hi @YongcaiHuang , thanks for the suggestion.

Can you elaborate what you mean by the cell range selection?

Note that right now you can select a subset of the rows using either the search box or the SearchPanes or SearchBuilder extensions and then if you download you'll get only the selected rows.

You can also pass select="multi" or "os" in the show function like, and then Ctrl+Click to select certain rows, and download only those:

show(
    df,
    buttons = ["copyHtml5", "csvHtml5", "excelHtml5"],
    select="os"
)

NB: with select="os" you get, in addition, the option to select ranges with Shift+Click.

YongcaiHuang commented 4 weeks ago

Hi @mwouts,

thank you for the suggection of using buttons and select argument. I have tried (see below video, also I am not sure why when I click copy button, there is a whole blank pop-up. Is this display error?), but cannot achieve what I mean

https://github.com/mwouts/itables/assets/97007177/4871e303-4f1f-4bba-a576-8b6d7c4d69f7

sorry for the vague description. for example, the expected results would be:

  1. command/shift/option/control + select cell A (like df.iloc[2, 2]) and cell B (like df.iloc[4, 4])

  2. a cell range is selected (like df.iloc[2:4, 2:4])

    image
  3. click copy button

  4. paste into Excel

I also tried keys argument, but a single cell can be selected.

mwouts commented 3 weeks ago

I see what you mean!

Well you can activate cell selection with e.g.

select={
        "style": "os",
        "items": "cell"
    }

but then, unlike for row selection, that's not taken into account by the export buttons. You can ask on the datatable forum if there is any way to export only the selected cells, as opposed to rows (assuming that the selection is a rectangle...)

Re the blank pop-up, on my end (firefox) I get a brief message with the number of rows copied. Can you try with a different browser?

YongcaiHuang commented 3 weeks ago

Thank you for the suggestion. I'll check in the datatable forum.

for the blank pop-up. I tried Jupyter lab desktop (4.2.1-1), Jupyter lab in Safari with version 17.5(19618.2.12.11.6) and Jupyter lab in edge (125.0.2535.79). Blank pop-up shows in all tries. However, when I change back to the Jupyter light theme, everything is back to normal

image

Then I tried the search builder, same issue happened as I mentioned here

image

Also, FYI, Jupyter Lab 4.2.0 has introduced the Dark High Contrast Theme, where display issue shows under this theme as well.

image

System: macOS Sonoma 14.5 Jupyter Lab: 4.2.1 itables: 2.1.0

mwouts commented 3 weeks ago

Thanks for reporting the issues with the Jupyter themes - I will have a look when times permit.

on46zohu commented 1 week ago

Hi @mwouts, is there any update on this? or any time planned?

mwouts commented 1 week ago

For the themes, could you try this?

from IPython.display import display, HTML

display(HTML("<script>document.documentElement.classList.add('dark');</script>"))

For the columns x row selection, you can use the column visibility button, combined with the export options like in the example below. You will be able to chose the columns that you want to see and export, and the rows:

show(
    df.reset_index(),
    select=True,
    buttons=[{"extend": "csv", "exportOptions": {"columns": ":visible"}}, "colvis"],
)
on46zohu commented 1 week ago

For the themes, could you try this?

from IPython.display import display, HTML

display(HTML("<script>document.documentElement.classList.add('dark');</script>"))

This one works great, thanks!