Advertisement
2345234523

OpenPYXL

Jun 26th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. Get sheet by name
  2. sheet = wb.get_sheet_by_name('Sheet1')
  3.  
  4. Is now....
  5.  
  6. sheet = wb['Sheet1']
  7.  
  8. +++++++++++++++++++++++++++++
  9.  
  10. Get sheet names
  11. wb.sheetnames
  12.  
  13. +++++++++++++++++++++++++++++
  14.  
  15. Get column LETTER
  16.  
  17. c.column
  18.  
  19. Is now....
  20.  
  21. c.column_letter
  22.  
  23.  
  24. +++++++++++++++++++++++++++++
  25.  
  26. Converting Between Column Letters and Numbers
  27. Import the following:
  28.  
  29. from openpyxl.utils import get_column_letter
  30. from openpyxl.utils import column_index_from_string
  31.  
  32. Commands:
  33. get_column_letter() - If you put in 1, you get A which is the first column.
  34.  
  35. column_index_from_string() - If you put in A, you get 1 which is the first column.
  36.  
  37. https://stackoverflow.com/questions/42913514/openpyxl-version-2-4-5-typeerror-generator-object-has-no-attribute-getitem/42913663#42913663
  38.  
  39. +++++++++++++++++++++++++++++
  40.  
  41. Accessing one column:
  42.  
  43. sheet['(Column Letter)']
  44.  
  45. x = sheet['B']
  46. print(x)
  47. +++++++++++++++++++++++++++++
  48.  
  49. Removing a worksheet
  50.  
  51. wb.remove_sheet(wb.get_sheet_by_name('Sheet Name'))
  52.  
  53. is Now...
  54.  
  55. del wb['Sheet name']
  56.  
  57. +++++++++++++++++++++++++++++
  58.  
  59. +++++++++++++++++++++++++++++
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement