Jun-20-2019, 12:40 PM
(This post was last modified: Jun-20-2019, 12:41 PM by CaptainCsaba.)
Hi!
I am trying to change some cells in excel with python. There is an error that sometimes occures in column K. Basically the "The number in this cell is formatted as text or preceded by an apostrophe". In excel you just click on the error and the click on convert to number to get rid of it.
You can't do this in Python but I figured out a way around it. If you put "1" in a cell and copy it, and the used Pastespecial on the column K with Values and Multiply as operation it fixes it. I can almost do this in Python but can't find the correct syntax for it.
https://analysistabs.com/vba-code/range/m/pastespecial/
It runs fine, but the problem still stands. What am i doing wrong, is there another way around this?
I am trying to change some cells in excel with python. There is an error that sometimes occures in column K. Basically the "The number in this cell is formatted as text or preceded by an apostrophe". In excel you just click on the error and the click on convert to number to get rid of it.
You can't do this in Python but I figured out a way around it. If you put "1" in a cell and copy it, and the used Pastespecial on the column K with Values and Multiply as operation it fixes it. I can almost do this in Python but can't find the correct syntax for it.
sheet['Z1'] = 1 from win32com.client import Dispatch excel = Dispatch("Excel.Application") excel.Visible = 1 source = excel.Workbooks.Open(mainworkingdirectory + "\\XYZ.xlsm") excel.Range("Z1").Select() excel.Selection.Copy() excel.Range("K:K").Select() excel.Selection.PasteSpecial(Paste = -4163, Operation = 4)The last line is wrong. I got the two numbers from here, -4163 stands for the "Values" and 4 is for the "Multiply":
https://analysistabs.com/vba-code/range/m/pastespecial/
It runs fine, but the problem still stands. What am i doing wrong, is there another way around this?