1 19 20 package jxl.write.biff; 21 22 import jxl.biff.Type; 23 import jxl.biff.StringHelper; 24 import jxl.biff.WritableRecordData; 25 26 29 class SortRecord extends WritableRecordData 30 { 31 private String column1Name; 32 private String column2Name; 33 private String column3Name; 34 private boolean sortColumns; 35 private boolean sortKey1Desc; 36 private boolean sortKey2Desc; 37 private boolean sortKey3Desc; 38 private boolean sortCaseSensitive; 39 40 52 public SortRecord(String a, String b, String c, 53 boolean sc, boolean sk1d, 54 boolean sk2d, boolean sk3d, boolean scs) 55 { 56 super(Type.SORT); 57 58 column1Name = a; 59 column2Name = b; 60 column3Name = c; 61 sortColumns = sc; 62 sortKey1Desc = sk1d; 63 sortKey2Desc = sk2d; 64 sortKey3Desc = sk3d; 65 sortCaseSensitive = scs; 66 } 67 68 73 public byte[] getData() 74 { 75 int byteCount = 5 + (column1Name.length() * 2) + 1; 76 if (column2Name.length() > 0) 77 byteCount += (column2Name.length() * 2) + 1; 78 if (column3Name.length() > 0) 79 byteCount += (column3Name.length() * 2) + 1; 80 byte[] data = new byte[byteCount + 1]; 81 int optionFlag = 0; 83 if (sortColumns) 84 optionFlag = optionFlag | 0x01; 85 if (sortKey1Desc) 86 optionFlag = optionFlag | 0x02; 87 if (sortKey2Desc) 88 optionFlag = optionFlag | 0x04; 89 if (sortKey3Desc) 90 optionFlag = optionFlag | 0x08; 91 if (sortCaseSensitive) 92 optionFlag = optionFlag | 0x10; 93 94 data[0] = (byte) optionFlag; 95 data[2] = (byte) column1Name.length(); 97 data[3] = (byte) column2Name.length(); 98 data[4] = (byte) column3Name.length(); 99 data[5] = 0x01; 101 StringHelper.getUnicodeBytes(column1Name, data, 6); 102 int curPos = 6 + (column1Name.length() * 2); 103 if (column2Name.length() > 0) 104 { 105 data[curPos++] = 0x01; 106 StringHelper.getUnicodeBytes(column2Name, data, curPos); 107 curPos += column2Name.length() * 2; 108 } 109 if (column3Name.length() > 0) 110 { 111 data[curPos++] = 0x01; 112 StringHelper.getUnicodeBytes(column3Name, data, curPos); 113 curPos += column3Name.length() * 2; 114 } 115 116 return data; 117 } 118 } 119 | Popular Tags |