0

I have a small Python script that writes data to an existing Excel file. The script is run from Ansys Workbench and in the Ansys installation python version is IronPython 2.7.4 for which Pandas (and some other libraries) is not available (to my understanding), therefore Python API Excel.Application is used for interacting with Excel.

Adding a new sheet and write data from Ansys works fine in the script, but now I would like to copy first sheet in Excel document and write data to it (only one workbook here). Problem is that I am stuck on the copy part, this is probably very simple thing to do, but the API Excel.Application is new to me. Is there a way to copy (rather than add) an excel sheet here?

(this is my first post at stackoverflow so question and code formatting may be not that advanced, thanks for your understanding).

import Microsoft.Office.Interop.Excel as Excel
# Excel file
filename = r”... \res.xlsx"
excel = Excel.ApplicationClass()
workbook = excel.Workbooks.Open(filename)
...
Sheet_new = ’s_1’
ws = workbook.Worksheets.Add()  # Create new sheet
ws.Name = Sheet_new 

Base is the name of excel sheet I want to copy

ws = workbook.Worksheets.Copy('Base')     # This did not work

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.