Good day. I am writing in despair.
For several days I have been trying to master at least something (openpyxl, xlsxwriter, xlrd-xlwt ...) that will help me accomplish the following, seemingly simple algorithm:
- Open Excel file.
- Find a cell in the defined column that matches the pre-defined word (in Russian).
- Copy the entire row along with this cell and all the data in this row (row).
- Create a new Excel file and write it all there (all the rows in which that predetermined word was found).
I tried exactly each of the modules. In some terrible troubles with receiving data from the string, others do not perceive the Russian language in the cells, others refuse to work at all ...
Here is the last failed example using win32com:
import win32com.client Excel = win32com.client.Dispatch("Excel.Application") text = 'Блендер' counter = 2 def write(val, pos): wb = Excel.Workbooks.Add() ws = wb.ActiveSheet i = 1 for rec in val: ws.Cells(pos,i).value = rec i = i + 1 wb.SaveAs('test.xlsx') wb.Close() Excel.Quit() def search(): wb = Excel.Workbooks.Open(u'C:/Users/User/Desktop/excel.xlsx') sheet = wb.ActiveSheet srch = [r[0].value for r in sheet.Range("B2:B13")] for items in srch: if text in items: global counter print ('Found') found = sheet.Range("A%s:D%s" % (counter,counter)).Value print (found) write(found,counter) counter += 1 search() Surely this code is as imperfect as possible. But let it be there at least over99 crutches, if only it worked, but it doesn’t work even with this - at the sight of a Russian text it falls into hysterics and shouts “OLE error NONE NONE”. And even without Russian characters, one FIG records only the first cell.
I will be infinitely glad to any help.
