• Microsoft .NET
  • C#.NET
  • Основы, лучшие методы и соглашения реализации событий в C#

Формат файла .bin Office 2007 - Часть таблицы

ОГЛАВЛЕНИЕ

Часть таблицы

Часть таблицы является новой концепцией в Excel 2007, добавляет большие улучшения к концепции объекта List, введенной в Excel 2003. Всегда, когда создается объект таблицы, на него ссылаются в листе следующим образом:

// Фрагмент части листа

...

<tableParts count="1">
94 05 (04) 01 00 00 00

<tablePart r:id="rId1"/>
95 05 (0c) 04 00 00 00 72 00 49 00 64 00 32 00

</tableParts>
96 05 (00)

...

Это прямо связано с отдельной частью, хранящейся в родительской папке tables, известной благодаря идентификатору отношения (rId1) и содержимому файла отношения (_rels/sheetxxx.bin.rels). Ниже приведена сама часть Table:

// Так часть таблицы выглядит в XML

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<table xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/5/main"
          id="1"
          name="Table1"
          displayName="Table1"
          ref="B2:D4"
          totalsRowShown="0">
  <autoFilter ref="B2:D4"/>
  <tableColumns count="3">
    <tableColumn id="1" name="Column1"/>
    <tableColumn id="2" name="2003"/>
    <tableColumn id="3" name="2004"/>
  </tableColumns>
  <tableStyleInfo
          name="TableStyleMedium9"
          showFirstColumn="0"
          showLastColumn="0"
          showRowStripes="1"
          showColumnStripes="0"/>
</table>

// Таким образом после разбиения части BIN на записи можно сопоставить
// записи с разметкой XML.

// Обратите внимание, что идентификаторы записей являются двумя байтами слева,
// связанная длина записи обрамлена круглыми скобками,
// а за ними идет само содержимое записи.


<table xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/5/main"
          id="1"
          name="Table1"
          displayName="Table1"
          ref="B2:D4"
          totalsRowShown="0">
d7 02 (64) 01 00 00 00 03 00 00 00 01 00 00 00 03 00 00 00 00 00 00
00 01 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 00 00
00 00 ff ff ff ff 06 00 00 00 54 00 61 00 62 00 6c 00 65 00 31 00 00
00 00 00 ff ff ff ff ff ff ff ff ff ff ff ff

<autoFilter ref="B2:D4">
a1 01 (10) 01 00 00 00 03 00 00 00 01 00 00 00 03 00 00 00

</autoFilter>
a2 01 (00)

<tableColumns count="3">
d9 02 (04) 03 00 00 00

<tableColumn id="1" name="Column1"/>
db 02 (3e) 01 00 00 00 00 00 00 00 ff ff ff ff ff ff ff ff ff ff ff ff
00 00 00 00 ff ff ff ff 07 00 00 00 43 00 6f 00 6c 00 75 00 6d 00 6e 00
31 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff

</tableColumn>
dc 02 (00)

<tableColumn id="2" name="2003">
db 02 (38) 02 00 00 00 00 00 00 00 ff ff ff ff ff ff ff ff ff ff ff ff
00 00 00 00 ff ff ff ff 04 00 00 00 32 00 30 00 30 00 33 00 ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff

</tableColumn>
dc 02 (00)

<tableColumn id="3" name="2004"/>
db 02 (38) 03 00 00 00 00 00 00 00 ff ff ff ff ff ff ff ff ff ff ff ff
00 00 00 00 ff ff ff ff 04
00 00 00 32 00 30 00 30 00 34 00 ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff

</tableColumn>
dc 02 (00)

</tableColumns>
da 02 (00)

<tableStyleInfo name="TableStyleMedium9"
                   showFirstColumn="0"
                   showLastColumn="0"
                   showRowStripes="1"
                   showColumnStripes="0"/>
81 04 (28) 04 00 11 00 00 00 54 00 61 00 62 00 6c 00 65 00 53 00 74 00 79
00 6c 00 65 00 4d 00 65 00 64 00 69 00 75 00 6d 00 39 00

</table>
d8 02 (00)

Задействуются следующие записи:

//записи таблицы
public const int BIFF12_TABLE           = 0x02D7;
public const int BIFF12_TABLE_END       = 0x02D8;
public const int BIFF12_TABLECOLUMNS    = 0x02D9;
public const int BIFF12_TABLECOLUMNS_END= 0x02DA;
public const int BIFF12_TABLECOLUMN     = 0x02DB;
public const int BIFF12_TABLECOLUMN_END = 0x02DC;
public const int BIFF12_AUTOFILTER      = 0x01A1;
public const int BIFF12_AUTOFILTER_END  = 0x01A2;
public const int BIFF12_FILTERCOLUMN    = 0x01A3;
public const int BIFF12_FILTERCOLUMN_END= 0x01A4;
public const int BIFF12_FILTERS         = 0x01A5;
public const int BIFF12_FILTERS_END     = 0x01A6;
public const int BIFF12_FILTER          = 0x01A7;
public const int BIFF12_TABLESTYLEINFO  = 0x0481;
public const int BIFF12_SORTSTATE       = 0x0492;
public const int BIFF12_SORTCONDITION   = 0x0494;
public const int BIFF12_SORTSTATE_END   = 0x0495;

Часть таблицы запроса

Часть таблицы запроса определяет источник данных. На таблицу запроса вообще не ссылаются в части листа. Это неявное поле в части Table, сделанное явным только в файле отношений, связанном с таблицей (i.e.tablexxx.bin.rels). Часть таблицы запроса выглядит так:

<queryTable name="Database1" connectionId="1" ...>
bf 03 (20) 49 1a 10 00 10 00
           01 00 00 00   connectionId
           09 00 00 00   length of string to follow
                           (in characters, not bytes)
           44 00 61 00 74 00 61 00 62 00 61 00 73 00 65 00 31 00
                               query table name

<queryTableRefresh nextId="5">
c1 03 (0a) 17 00 05 00 00 00 00 00 00 00

<queryTableFields count="4">
c7 03 (04) 04 00 00 00

<queryTableField id="1" name="ID" tableColumnId="1">
c9 03 (14) 10 00 00 00
           01 00 00 00 query table field id
           01 00 00 00 table column id
           02 00 00 00 length of string to follow
                           (in characters, not bytes)
           49 00 44 00 query table field name

</queryTableField>
ca 03 (00)

<queryTableField id="2" name="TB_Name" tableColumnId="2">
c9 03 (1e) 10 00 00 00
           02 00 00 00 query table field id
           02 00 00 00 table column id
           07 00 00 00 length of string to follow
                           (in characters, not bytes)
           54 00 42 00 5f 00 4e 00 61 00 6d 00 65 00
                           query table field name

</queryTableField>
ca 03 (00)

<queryTableField id="3" name="TB_AGE" tableColumnId="3">
c9 03 (1c) 10 00 00 00
           03 00 00 00 query table field id
           03 00 00 00 table column id
           06 00 00 00 length of string to follow
                           (in characters, not bytes)
           54 00 42 00 5f 00 41 00 47 00 45 00
                           query table field name

</queryTableField>
ca 03 (00)

<queryTableField id="4" name="TB_COUNTRY" tableColumnId="4">
c9 03 (24) 10 00 00 00
           04 00 00 00 query table field id
           04 00 00 00 table column id
           0a 00 00 00 length of string to follow
                           (in characters, not bytes)
           54 00 42 00 5f 00 43 00 4f 00 55 00 4e 00 54 00 52 00 59 00
                           query table field name

</queryTableField>
ca 03 (00)

</queryTableFields>
c8 03 (00)

</queryTableRefresh>
c2 03 (00)

</queryTable>
c0 03 (00)

Задействуются следующие записи:

//записи таблицы запроса
public const int BIFF12_QUERYTABLE            = 0x03BF;
public const int BIFF12_QUERYTABLE_END        = 0x03C0;
public const int BIFF12_QUERYTABLEREFRESH     = 0x03C1;
public const int BIFF12_QUERYTABLEREFRESH_END = 0x03C2;
public const int BIFF12_QUERYTABLEFIELDS      = 0x03C7;
public const int BIFF12_QUERYTABLEFIELDS_END  = 0x03C8;
public const int BIFF12_QUERYTABLEFIELD       = 0x03C9;
public const int BIFF12_QUERYTABLEFIELD_END   = 0x03CA;