You've already forked lazarus-ccr
spready: SYLK reader supports numberformat, shaded background and cell border.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7094 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -34,6 +34,7 @@ type
|
|||||||
procedure ProcessCell(const AFields: TsSYLKFields);
|
procedure ProcessCell(const AFields: TsSYLKFields);
|
||||||
procedure ProcessFormat(const AFields: TsSYLKFields);
|
procedure ProcessFormat(const AFields: TsSYLKFields);
|
||||||
procedure ProcessLine(const ALine: String);
|
procedure ProcessLine(const ALine: String);
|
||||||
|
procedure ProcessNumFormat(const AFields: TsSYLKFields);
|
||||||
procedure ProcessRecord(ARecordType: String; const AFields: TsSYLKFields);
|
procedure ProcessRecord(ARecordType: String; const AFields: TsSYLKFields);
|
||||||
public
|
public
|
||||||
constructor Create(AWorkbook: TsBasicWorkbook); override;
|
constructor Create(AWorkbook: TsBasicWorkbook); override;
|
||||||
@ -209,19 +210,40 @@ var
|
|||||||
col, row, col1, col2: LongInt;
|
col, row, col1, col2: LongInt;
|
||||||
ch1, ch2: Char;
|
ch1, ch2: Char;
|
||||||
nf: TsNumberFormat;
|
nf: TsNumberFormat;
|
||||||
|
nfs: String;
|
||||||
decs: Integer;
|
decs: Integer;
|
||||||
ha: TsHorAlignment;
|
ha: TsHorAlignment;
|
||||||
|
hasStyle: Boolean;
|
||||||
|
fill: Boolean;
|
||||||
val: Double;
|
val: Double;
|
||||||
P: PChar;
|
P: PChar;
|
||||||
|
n: Integer;
|
||||||
sheet: TsWorksheet;
|
sheet: TsWorksheet;
|
||||||
|
dest: Integer; // 0=cell format, 1=col format, 2=rowFormat
|
||||||
|
fmt: TsCellFormat;
|
||||||
|
fmtIdx: Integer;
|
||||||
|
b: TsCellBorders;
|
||||||
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
sheet := FWorksheet as TsWorksheet;
|
sheet := FWorksheet as TsWorksheet;
|
||||||
|
|
||||||
nf := nfGeneral;
|
nf := nfGeneral;
|
||||||
ha := haDefault;
|
ha := haDefault;
|
||||||
decs := 0;
|
decs := 0;
|
||||||
|
fill := false;
|
||||||
|
b := [];
|
||||||
|
InitFormatRecord(fmt);
|
||||||
|
|
||||||
// Format
|
// Format
|
||||||
|
nfs := '';
|
||||||
|
s := GetFieldValue(AFields, 'P');
|
||||||
|
if (s <> '') then begin
|
||||||
|
if LowerCase(s) = 'general' then
|
||||||
|
nf := nfGeneral
|
||||||
|
else if TryStrToInt(s, n) then
|
||||||
|
nfs := FNumFormatList[n];
|
||||||
|
end;
|
||||||
|
|
||||||
s := GetFieldValue(AFields, 'F');
|
s := GetFieldValue(AFields, 'F');
|
||||||
if s <> '' then
|
if s <> '' then
|
||||||
begin
|
begin
|
||||||
@ -252,24 +274,26 @@ begin
|
|||||||
'L': ha := haLeft;
|
'L': ha := haLeft;
|
||||||
'R': ha := haRight;
|
'R': ha := haRight;
|
||||||
'-': ; // ???
|
'-': ; // ???
|
||||||
'X': ; // "Fill"
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Determine whether the format applies to column, row or
|
// Style
|
||||||
|
s := GetFieldValue(AFields, 'S');
|
||||||
|
if s <> '' then begin
|
||||||
|
for i := 1 to Length(s) do begin
|
||||||
|
ch1 := s[i];
|
||||||
|
case ch1 of
|
||||||
|
'S': fill := true;
|
||||||
|
'T': Include(b, cbNorth);
|
||||||
|
'L': Include(b, cbWest);
|
||||||
|
'R': Include(b, cbEast);
|
||||||
|
'B': Include(b, cbSouth);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
(*
|
// Determin to which cell, column or row the format applies
|
||||||
scol := GetFieldValue(AFields, 'C');
|
dest := 0; // assume cell format
|
||||||
// Column format, not supported yet
|
|
||||||
if scol <> '' then
|
|
||||||
exit;
|
|
||||||
|
|
||||||
srow := GetFieldValue(AFields, 'R');
|
|
||||||
// Row format, not yet supported
|
|
||||||
if srow <> '' then
|
|
||||||
exit;
|
|
||||||
*)
|
|
||||||
|
|
||||||
// Cell format
|
|
||||||
scol := GetFieldValue(AFields, 'X');
|
scol := GetFieldValue(AFields, 'X');
|
||||||
if (scol <> '') and TryStrToInt(scol, col) then begin
|
if (scol <> '') and TryStrToInt(scol, col) then begin
|
||||||
dec(col);
|
dec(col);
|
||||||
@ -284,21 +308,65 @@ begin
|
|||||||
end else
|
end else
|
||||||
row := FPrevY;
|
row := FPrevY;
|
||||||
|
|
||||||
if (row >= FNumRows) then begin
|
if (row >= FNumRows) and (FNumRows > 0) then begin
|
||||||
FWorkbook.AddErrorMsg('line %d, %s": column is outside range.', [FLineNumber, FRecordLine]);
|
FWorkbook.AddErrorMsg('line %d, %s": row %d is outside range.', [FLineNumber, FRecordLine, row]);
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if (col >= FNumCols) then begin
|
if (col >= FNumCols) and (FNumCols > 0) then begin
|
||||||
FWorkbook.AddErrorMsg('line%d, "%s": row is outside range.', [FLineNumber, FRecordLine]);
|
FWorkbook.AddErrorMsg('line%d, "%s": column %d is outside range.', [FLineNumber, FRecordLine, col]);
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Cell format
|
// Column format
|
||||||
|
scol := GetFieldValue(AFields, 'C');
|
||||||
|
if (scol <> '') and TryStrToInt(scol, col) then begin
|
||||||
|
dec(col);
|
||||||
|
dest := 1; // is column format
|
||||||
|
end;
|
||||||
|
|
||||||
|
// Row format
|
||||||
|
srow := GetFieldValue(AFields, 'R');
|
||||||
|
if (srow <> '') and TryStrToInt(srow, row) then begin
|
||||||
|
dec(row);
|
||||||
|
dest := 2; // is row format
|
||||||
|
end;
|
||||||
|
|
||||||
|
// Create format record and store in workbook format list
|
||||||
|
if ha <> haDefault then begin
|
||||||
|
fmt.HorAlignment := ha;
|
||||||
|
Include(fmt.UsedFormattingfields, uffHorAlign);
|
||||||
|
end;
|
||||||
|
if fill then begin
|
||||||
|
fmt.Background.Style := fsGray25;
|
||||||
|
fmt.Background.FgColor := scBlack;
|
||||||
|
fmt.Background.BgColor := scTransparent;
|
||||||
|
Include(fmt.UsedFormattingFields, uffBackground);
|
||||||
|
end;
|
||||||
|
if b <> [] then begin
|
||||||
|
fmt.Border := b;
|
||||||
|
Include(fmt.UsedFormattingFields, uffBorder);
|
||||||
|
end;
|
||||||
|
if (nfs = '') then begin
|
||||||
|
if nf in [nfCurrency, nfCurrencyRed] then
|
||||||
|
nfs := BuildCurrencyFormatString(nf, FWorkbook.FormatSettings, decs, -1, -1, '?', false)
|
||||||
|
else
|
||||||
|
nfs := BuildNumberFormatString(nf, FWorkbook.FormatSettings, decs);
|
||||||
|
end;
|
||||||
|
if (nfs <> '') and (nfs <> 'General') then begin
|
||||||
|
fmt.NumberFormatIndex := TsWorkbook(FWorkbook).AddNumberFormat(nfs);
|
||||||
|
Include(fmt.UsedFormattingFields, uffNumberFormat);
|
||||||
|
end;
|
||||||
|
fmtIdx := TsWorkbook(FWorkbook).AddCellFormat(fmt);
|
||||||
|
|
||||||
|
// Apply format to cell, col or row
|
||||||
|
case dest of
|
||||||
|
0: begin
|
||||||
cell := sheet.GetCell(row, col);
|
cell := sheet.GetCell(row, col);
|
||||||
sheet.WriteNumberFormat(cell, nf, decs);
|
sheet.WriteCellFormatIndex(cell, fmtIdx);
|
||||||
sheet.WriteHorAlignment(cell, ha);
|
end;
|
||||||
|
1: sheet.WriteColFormatIndex(col, fmtIdx);
|
||||||
|
2: sheet.WriteRowFormatIndex(row, fmtIdx);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Column width
|
// Column width
|
||||||
@ -397,6 +465,14 @@ begin
|
|||||||
ProcessRecord(rtd, fields);
|
ProcessRecord(rtd, fields);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TsSYLKReader.ProcessNumFormat(const AFields: TsSYLKFields);
|
||||||
|
var
|
||||||
|
s: String;
|
||||||
|
begin
|
||||||
|
s := GetFieldValue(AFields, 'P');
|
||||||
|
FNumFormatList.Add(s);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TsSYLKReader.ProcessRecord(ARecordType: String;
|
procedure TsSYLKReader.ProcessRecord(ARecordType: String;
|
||||||
const AFields: TsSYLKFields);
|
const AFields: TsSYLKFields);
|
||||||
begin
|
begin
|
||||||
@ -405,6 +481,7 @@ begin
|
|||||||
'B' : ProcessBounds(AFields); // Bounds of the sheet
|
'B' : ProcessBounds(AFields); // Bounds of the sheet
|
||||||
'C' : ProcessCell(AFields); // Content record
|
'C' : ProcessCell(AFields); // Content record
|
||||||
'F' : ProcessFormat(AFields); // Format record
|
'F' : ProcessFormat(AFields); // Format record
|
||||||
|
'P' : ProcessNumFormat(AFields); // Excel number format
|
||||||
'E' : ; // End of file
|
'E' : ; // End of file
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -422,6 +499,7 @@ var
|
|||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
Unused(AParams);
|
Unused(AParams);
|
||||||
|
FNumFormatList.Clear;
|
||||||
|
|
||||||
// Create worksheet
|
// Create worksheet
|
||||||
FWorksheet := (FWorkbook as TsWorkbook).AddWorksheet(FWorksheetName, true);
|
FWorksheet := (FWorkbook as TsWorkbook).AddWorksheet(FWorksheetName, true);
|
||||||
|
Reference in New Issue
Block a user