Fixes and improvements

This commit is contained in:
csh
2025-02-14 15:26:26 +08:00
parent 41bbf69f79
commit 958b62f72c
10 changed files with 1259 additions and 291 deletions
-64
View File
@@ -1,64 +0,0 @@
type XlsxSheetData = class
public
function Create(sheet_data: SheetData);
function Operator[](index: integer): XlsxSheetDataRow;
function Cell(r: integer; c: integer): C;
function Rows(index: integer): XlsxSheetDataRow;
function Serialize();
private
rows_: array of XlsxSheetDataRow;
sheet_data_: SheetData;
end;
function XlsxSheetData.Create(sheet_data: SheetData);
begin
rows_ := array();
sheet_data_ := sheet_data;
rows := sheet_data.Rows();
for i:=0 to length(rows)-1 do
begin
r := strToInt(rows[i].R);
rows_[r] := new XlsxSheetDataRow(rows[i]);
end
// println("rows = {}", rows_);
end;
function Operator XlsxSheetData.[](index: integer): XlsxSheetDataRow;
begin
if ifnil(rows_[index]) and tslassigning then
begin
row := new Row(sheet_data_, "", "row");
rows_[index] := new XlsxSheetDataRow(row);
pos := -1;
for k,_ in rows_ do // TODO:此处弊端是要遍历所有k,可考虑维护一个新array,用二分
if pos < k and k < index then pos := k;
pos = -1 ? sheet_data_.AppendChild(row) : sheet_data_.InsertAfter(row, rows_[pos].Data());
end
return rows_[index];
end;
function XlsxSheetData.Rows(index: integer): XlsxSheetDataRow;
begin
return self[index];
end;
function XlsxSheetData.Cell(r: integer; c: integer): C;
begin
bk := tslassigning;
tslassigning := 1;
c := self[r][c];
tslassigning := bk;
return c;
end;
function XlsxSheetData.Serialize();
begin
for k,row in rows_ do
begin
r := row.Data();
r.R := k;
row.Serialize();
end
// sheet_data_.Serialize();
end;
-63
View File
@@ -1,63 +0,0 @@
type XlsxSheetDataRow = class
public
function Create(row: Row);
function Operator[](index: integer): XlsxSheetDataCol;
function Cols(index: integer): XlsxSheetDataCol;
function Data(): Row;
function Serialize();
public
row_: Row;
cols_: array of XlsxSheetDataCol;
end;
function XlsxSheetDataRow.Create(row: Row);
begin
row_ := row;
cols_ := array();
cs := row.Cs();
for i:=0 to length(cs)-1 do
begin
r := cs[i].R;
cell_name := SplitCellName(r);
index := ColumnNameToNumber(cell_name[1])[1];
cols_[index] := cs[i];
end
// println("cols_ = {}", cols_);
end;
function Operator XlsxSheetDataRow.[](index: integer): XlsxSheetDataCol;
begin
if ifnil(cols_[index]) and tslassigning then
begin
col := new C(row_, "", "c");
cols_[index] := col;
pos := -1;
for k,_ in cols_ do
if pos < k and k < index then pos := k;
pos = -1 ? row_.AppendChild(col) : row_.InsertAfter(col, cols_[pos]);
end
return cols_[index];
end;
function XlsxSheetDataRow.Cols(index: integer): XlsxSheetDataCol;
begin
return self[index];
end;
function XlsxSheetDataRow.Data(): Row;
begin
return row_;
end;
function XlsxSheetDataRow.Serialize();
begin
for k,c in cols_ do
begin
c.R := CoordinatesToCellName(k, row_.R)[1];
c.Serialize();
// println("c.R = {}, row.R = {}", c.R, row_.R);
end
row_.Serialize();
end;