Column.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # -*- coding: windows-1252 -*-
  2. from .BIFFRecords import ColInfoRecord
  3. class Column(object):
  4. def __init__(self, colx, parent_sheet):
  5. if not(isinstance(colx, int) and 0 <= colx <= 255):
  6. raise ValueError("column index (%r) not an int in range(256)" % colx)
  7. self._index = colx
  8. self._parent = parent_sheet
  9. self._parent_wb = parent_sheet.get_parent()
  10. self._xf_index = 0x0F
  11. self.width = 0x0B92
  12. self.hidden = 0
  13. self.level = 0
  14. self.collapse = 0
  15. self.user_set = 0
  16. self.best_fit = 0
  17. self.unused = 0
  18. def set_width(self, width):
  19. if not(isinstance(width, int) and 0 <= width <= 65535):
  20. raise ValueError("column width (%r) not an int in range(65536)" % width)
  21. self._width = width
  22. def get_width(self):
  23. return self._width
  24. width = property(get_width, set_width)
  25. def set_style(self, style):
  26. self._xf_index = self._parent_wb.add_style(style)
  27. def width_in_pixels(self):
  28. # *** Approximation ****
  29. return int(round(self.width * 0.0272 + 0.446, 0))
  30. def get_biff_record(self):
  31. options = (self.hidden & 0x01) << 0
  32. options |= (self.user_set & 0x01) << 1
  33. options |= (self.best_fit & 0x01) << 2
  34. options |= (self.level & 0x07) << 8
  35. options |= (self.collapse & 0x01) << 12
  36. return ColInfoRecord(self._index, self._index, self.width, self._xf_index, options, self.unused).get()