# -*- coding: windows-1252 -*- from struct import unpack, pack from . import BIFFRecords from .compat import xrange class StrCell(object): __slots__ = ["rowx", "colx", "xf_idx", "sst_idx"] def __init__(self, rowx, colx, xf_idx, sst_idx): self.rowx = rowx self.colx = colx self.xf_idx = xf_idx self.sst_idx = sst_idx def get_biff_data(self): # return BIFFRecords.LabelSSTRecord(self.rowx, self.colx, self.xf_idx, self.sst_idx).get() return pack('<5HL', 0x00FD, 10, self.rowx, self.colx, self.xf_idx, self.sst_idx) class BlankCell(object): __slots__ = ["rowx", "colx", "xf_idx"] def __init__(self, rowx, colx, xf_idx): self.rowx = rowx self.colx = colx self.xf_idx = xf_idx def get_biff_data(self): # return BIFFRecords.BlankRecord(self.rowx, self.colx, self.xf_idx).get() return pack('<5H', 0x0201, 6, self.rowx, self.colx, self.xf_idx) class MulBlankCell(object): __slots__ = ["rowx", "colx1", "colx2", "xf_idx"] def __init__(self, rowx, colx1, colx2, xf_idx): self.rowx = rowx self.colx1 = colx1 self.colx2 = colx2 self.xf_idx = xf_idx def get_biff_data(self): return BIFFRecords.MulBlankRecord(self.rowx, self.colx1, self.colx2, self.xf_idx).get() class NumberCell(object): __slots__ = ["rowx", "colx", "xf_idx", "number"] def __init__(self, rowx, colx, xf_idx, number): self.rowx = rowx self.colx = colx self.xf_idx = xf_idx self.number = float(number) def get_encoded_data(self): rk_encoded = 0 num = self.number # The four possible kinds of RK encoding are *not* mutually exclusive. # The 30-bit integer variety picks up the most. # In the code below, the four varieties are checked in descending order # of bangs per buck, or not at all. # SJM 2007-10-01 if -0x20000000 <= num < 0x20000000: # fits in 30-bit *signed* int inum = int(num) if inum == num: # survives round-trip # print "30-bit integer RK", inum, hex(inum) rk_encoded = 2 | (inum << 2) return 1, rk_encoded temp = num * 100 if -0x20000000 <= temp < 0x20000000: # That was step 1: the coded value will fit in # a 30-bit signed integer. itemp = int(round(temp, 0)) # That was step 2: "itemp" is the best candidate coded value. # Now for step 3: simulate the decoding, # to check for round-trip correctness. if itemp / 100.0 == num: # print "30-bit integer RK*100", itemp, hex(itemp) rk_encoded = 3 | (itemp << 2) return 1, rk_encoded if 0: # Cost of extra pack+unpack not justified by tiny yield. packed = pack('