Inserting text into Excel with Python creates Bubbles -


using python enter text excel file, have little problem occurs excel 2010. working excel 2013. i've tested on 2 different pc's. on 1 pc excel 2010, excel crashes, on other, enters these kind of bubbles (they behave images - can resize them):

enter image description here

the code works this: create string, indicating line changes \r\n, , pasting excel.dispatchand pastespecial.

what can reason not inserting correctly?

def pastetoexcel(excelfile, sheet, data, startcell):     if type(data) == list:         rows = 1         cols = len(data)     elif type(data) == pd.dataframe:         rows = data.shape[0]         cols = data.shape[1]     elif type(data) == int or float:         rows = 1         cols = 1     elif type(data) == str:         rows = 1         cols = 1      cellrange = startcell     text = ""      cellrange = calculatecellrange(startcell,rowcount=rows,colcount=cols)      if type(data) == pd.dataframe:         print "  erkannter datentyp vom input: pd.dataframe"         line_strings = []         row in range(rows):             col in range(cols-1):                  line_strings.append(str(data.ix[row,col])+"\t") #cell change: \t             line_strings.append(str(data.ix[row,data.shape[1]-1])+"\r\n")          item in line_strings:             item = item.replace(".",",")             text += item      elif type(data) == str:         text = data      elif type(data) == list:         line_strings = []         index in range(len(data)): # 0 1 2           len(data) =3 ; range(2) = 0,1             if index < len(data)-1:                 line_strings.append(str(data[index])+"\t") #cell change: \t             elif index == len(data)-1:                 line_strings.append(str(data[index])+"\r\n")          item in line_strings:             item = item.replace(".",",")             text += item      clipboard.openclipboard()     clipboard.emptyclipboard()     clipboard.setclipboardtext(text)     clipboard.closeclipboard()      excel = dispatch("excel.application")     excel.visible = 0     wb = excel.workbooks.open(excelfile)      ws = wb.worksheets(sheet)     ws.activate()     ws.range(cellrange).select()     wb.activesheet.pastespecial()     excel.displayalerts = false     excel.activeworkbook.save()     excel.quit() 


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -