Python Excel Copy data without Formulas

1793 views python
1

I tried to copy and paste some data from 2 different excel workbook with Win32 but in the Target wb I always have the formulas of the Source. The code works but I only need the value.

wb0 = excel.Workbooks.Open(pathSource)
ws0 = wb0.Worksheets('wsSource')
wb2 = excel.Workbooks.Open(pathTarget)
ws2 = wb2.Worksheets('wsTarget')
ws2.Name = 'NB DATA'
ws0 = wb0.Worksheets('wsTarget')
ws0.Range(datacopied).Copy(ws2.Range(datacopied))
wb2.Save()

answered question

What is contained in the datacopied variable?

1 Answer

12

Looking back on your previous questions, I see you asked this before and it had more example code in the question.

I think what you may be looking for is this:

wb0 = excel.Workbooks.Open(pathSource)
ws0 = wb0.Worksheets('wsSource')
wb2 = excel.Workbooks.Open(pathTarget)
ws2 = wb2.Worksheets('wsTarget')
ws2.Name = 'NB DATA'
ws0 = wb0.Worksheets('wsTarget')
ws2.Range(datacopied).Value = ws0.Range(datacopied).Value
wb2.Save()

Taking the value of the range, and not simply copying it's contents is what you want it sounds like.

posted this

Have an answer?

JD

Please login first before posting an answer.