简体   繁体   English

从打开的 excel 文件级别检索 pandas dataframe

[英]Retrieving pandas dataframe from open excel file level

I would like to use a VBA macro in an excel spreadsheet that pastes specific dataframe from my jupyter notebook into this spreadheet.我想在 excel 电子表格中使用 VBA 宏,该电子表格将我的 jupyter 笔记本中的特定 dataframe 粘贴到此电子表格中。

I tried what was suggested in other thread but the code doesn't say how to specify a df that I need.我尝试了其他线程中的建议,但代码没有说明如何指定我需要的 df。

This is what I used这是我用的

Sub DataFrameImport()
  'RUN PYTHON TO EXPORT DATA FRAME
  Shell "C:\pathTo\python.exe fullpathOfPythonScript.py", vbNormalFocus

  'CLEAR EXISTING CONTENT
  ThisWorkbook.Worksheets(5).Cells.Clear

  'COPY AND PASTE TO WORKBOOK
  Workbooks("PythonExport").Worksheets(1).Cells.Copy
  ThisWorkbook.Worksheets(5).Range("A1").Select
  ThisWorkbook.Worksheets(5).Paste
End Sub

Have a look at this library: https://www.xlwings.org/ .看看这个库: https://www.xlwings.org/ It allows you to call python from VBA in a very intuitive manner as described in the documentation here .它允许您以非常直观的方式从 VBA 调用 python,如此文档中所述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM