SHARE
TWEET

Untitled

a guest Apr 21st, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from openpyxl.workbook import Workbook
  2. from openpyxl.utils import get_column_letter
  3. from openpyxl import load_workbook
  4.  
  5.  
  6. def main():
  7.     wbr = load_workbook(filename='ОПК ГИСП - общая_2.xlsx')
  8.     sheet = wbr['Лист1']
  9.  
  10.     counter = 1
  11.     file_div = 500
  12.     total_files = (sheet.max_row // file_div) + 1
  13.     file_counter = 0
  14.     offset = 0
  15.  
  16.     while file_counter < total_files:
  17.         wb = Workbook()
  18.         ws1 = wb.active
  19.         ws1.title = "data"
  20.  
  21.         if file_counter != 0:
  22.             ws1.append((cell.value for cell in sheet[1][0:20]))
  23.  
  24.         for row in sheet.iter_rows(file_counter * file_div + offset + 1, (file_counter + 1) * file_div):
  25.             ws1.append((cell.value for cell in row[0:20]))
  26.  
  27.         offset = 0
  28.         i = (file_counter + 1) * file_div
  29.         while sheet[i][0].value == sheet[i + 1][0].value:
  30.             print(offset)
  31.             print(sheet[i][0].value, sheet[i + 1][0].value)
  32.             row = sheet[i + 1]
  33.             ws1.append((cell.value for cell in row[0:20]))
  34.             offset += 1
  35.             i += 1
  36.  
  37.         dest_filename = filename.split('.')[-2] + '_' + str(counter) + '.xlsx'
  38.         counter += 1
  39.         file_counter += 1
  40.         wb.save(filename=dest_filename)
  41.  
  42.  
  43. if __name__ == '__main__':
  44.     main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top