133 lines
3.3 KiB
Plaintext
133 lines
3.3 KiB
Plaintext
Type TSDocxColumn = Class(TSVbaBase)
|
|
Uses TSDocxEnumerations;
|
|
|
|
public
|
|
Function Init(table, column);
|
|
|
|
private
|
|
Function SerializeTblGrid();
|
|
|
|
private
|
|
table_;
|
|
column_;
|
|
cells_;
|
|
|
|
public
|
|
// Methods
|
|
Function AutoFit();
|
|
Function Delete();
|
|
Function Select();
|
|
Function SetWidth(ColumnWidth, RulerStyle);
|
|
Function Sort(ExcludeHeader, SortFieldType, SortOrder, CaseSensitive, BidiSort, IgnoreThe, IgnoreKashida, IgnoreDiacritics, IgnoreHe, LanguageID);
|
|
|
|
// Properties
|
|
property Borders read ReadBorders;
|
|
property Cells read ReadCells;
|
|
property Index read ReadIndex;
|
|
property IsFirst read ReadIsFirst;
|
|
property IsLast read ReadIsLast;
|
|
property NestingLevel read ReadNestingLevel;
|
|
property Next read ReadNext;
|
|
property PreferredWidth read ReadPreferredWidth write WritePreferredWidth;
|
|
property PreferredWidthType read ReadPreferredWidthType write WritePreferredWidthType;
|
|
property Previous read ReadPrevious;
|
|
property Shading read ReadShading;
|
|
property Width read ReadWidth write WriteWidth;
|
|
Function WriteWidth(value);
|
|
Function ReadWidth();
|
|
Function ReadShading();
|
|
Function ReadPrevious();
|
|
Function WritePreferredWidthType(value);
|
|
Function ReadPreferredWidthType();
|
|
Function WritePreferredWidth(value);
|
|
Function ReadPreferredWidth();
|
|
Function ReadNext();
|
|
Function ReadNestingLevel();
|
|
Function ReadIsLast();
|
|
Function ReadIsFirst();
|
|
Function ReadIndex();
|
|
Function ReadCells(n);
|
|
Function ReadBorders();
|
|
|
|
End;
|
|
|
|
// ============== 实现 ================= //
|
|
Function TSDocxColumn.Init(table, column);
|
|
Begin
|
|
table_ := table;
|
|
column_ := column;
|
|
cells_ := new TSDocxCells(self.Application, self.Creator, self);
|
|
cells_.Init(table_, nil, column_);
|
|
End;
|
|
|
|
Function TSDocxColumn.SerializeTblGrid();
|
|
Begin
|
|
grid_col_arr := array();
|
|
total_width := 0;
|
|
grid_col := class(TSXml).GetNode(table_.Root(), "w:tblGrid/w:gridCol");
|
|
while ifObj(grid_col) do
|
|
begin
|
|
ww := strtoint(grid_col.GetAttribute("w:w"));
|
|
total_width += ww;
|
|
grid_col_arr[length(grid_col_arr)] := array(grid_col, ww);
|
|
grid_col := grid_col.NextElement();
|
|
end
|
|
return array(total_width, grid_col_arr);
|
|
End;
|
|
|
|
// Methods
|
|
Function TSDocxColumn.SetWidth(ColumnWidth, RulerStyle);
|
|
Begin
|
|
[total_width, grid_col_arr] := SerializeTblGrid();
|
|
// 设置w:tblPr的总宽度
|
|
table_.TblPr.Width := total_width;
|
|
table_.TblPr.WidthType := "dxa";
|
|
table_.TblPr.Update();
|
|
|
|
// 不再调整列宽 "w:tblGrid/w:gridCol",复杂表格列数不好判定
|
|
for i:=1 to table_.Rows() do
|
|
self.Cells(i).SetWidth(ColumnWidth, RulerStyle);
|
|
|
|
End;
|
|
|
|
// Properties
|
|
Function TSDocxColumn.WriteWidth(value);
|
|
Begin
|
|
for i:=1 to table_.Rows() do
|
|
self.Cells(i).Width := value;
|
|
End;
|
|
Function TSDocxColumn.ReadWidth();
|
|
Begin
|
|
return self.Cells(1).Width;
|
|
End;
|
|
|
|
Function TSDocxColumn.WritePreferredWidthType(value);
|
|
Begin
|
|
for i:=1 to table_.Rows() do
|
|
self.Cells(i).PreferredWidthType := value;
|
|
End;
|
|
Function TSDocxColumn.ReadPreferredWidthType();
|
|
Begin
|
|
return self.Cells(1).PreferredWidthType;
|
|
End;
|
|
|
|
Function TSDocxColumn.WritePreferredWidth(value);
|
|
Begin
|
|
for i:=1 to table_.Rows() do
|
|
self.Cells(i).PreferredWidth := value;
|
|
End;
|
|
Function TSDocxColumn.ReadPreferredWidth();
|
|
Begin
|
|
return self.Cells(1).PreferredWidth;
|
|
End;
|
|
|
|
Function TSDocxColumn.ReadIndex();
|
|
Begin
|
|
return column_;
|
|
End;
|
|
|
|
Function TSDocxColumn.ReadCells(n);
|
|
Begin
|
|
return ifnil(n) ? cells_: cells_.Item(n);
|
|
End;
|