You've already forked lazarus-ccr
fpspreadsheet: Write column and row formats to xlsx
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5253 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -3241,6 +3241,7 @@ type
|
|||||||
var
|
var
|
||||||
rec: TColRecord;
|
rec: TColRecord;
|
||||||
w: Integer;
|
w: Integer;
|
||||||
|
width: Single;
|
||||||
begin
|
begin
|
||||||
if Assigned(ACol) then
|
if Assigned(ACol) then
|
||||||
begin
|
begin
|
||||||
@ -3256,7 +3257,13 @@ begin
|
|||||||
rec.EndCol := WordToLE(ACol^.Col);
|
rec.EndCol := WordToLE(ACol^.Col);
|
||||||
|
|
||||||
{ calculate width to be in units of 1/256 of pixel width of character "0" }
|
{ calculate width to be in units of 1/256 of pixel width of character "0" }
|
||||||
w := round(FWorkbook.ConvertUnits(ACol^.Width, FWorkbook.Units, suChars)*256);
|
case ACol^.ColWidthType of
|
||||||
|
cwtDefault:
|
||||||
|
width := FWorksheet.ReadDefaultColWidth(suChars);
|
||||||
|
cwtCustom:
|
||||||
|
width := FWorkbook.ConvertUnits(ACol^.Width, FWorkbook.Units, suChars);
|
||||||
|
end;
|
||||||
|
w := round(width * 256);
|
||||||
|
|
||||||
rec.ColWidth := WordToLE(w);
|
rec.ColWidth := WordToLE(w);
|
||||||
rec.XFIndex := WordToLE(FindXFIndex(ACol^.FormatIndex));// Index of XF record
|
rec.XFIndex := WordToLE(FindXFIndex(ACol^.FormatIndex));// Index of XF record
|
||||||
|
@ -2526,23 +2526,32 @@ end;
|
|||||||
|
|
||||||
procedure TsSpreadOOXMLWriter.WriteCols(AStream: TStream; AWorksheet: TsWorksheet);
|
procedure TsSpreadOOXMLWriter.WriteCols(AStream: TStream; AWorksheet: TsWorksheet);
|
||||||
var
|
var
|
||||||
col: PCol;
|
lCol: PCol;
|
||||||
c: Integer;
|
c: Integer;
|
||||||
w: Single;
|
w: Single;
|
||||||
|
customWidth: String;
|
||||||
|
customStyle: String;
|
||||||
begin
|
begin
|
||||||
AppendToStream(AStream,
|
AppendToStream(AStream,
|
||||||
'<cols>');
|
'<cols>');
|
||||||
|
|
||||||
for c:=0 to AWorksheet.GetLastColIndex do begin
|
for c:=0 to AWorksheet.GetLastColIndex do begin
|
||||||
col := AWorksheet.FindCol(c);
|
customWidth := '';
|
||||||
|
customStyle := '';
|
||||||
|
lCol := AWorksheet.FindCol(c);
|
||||||
|
|
||||||
// The column width is needed in suChars here.
|
// The column width is needed in suChars here.
|
||||||
if col <> nil then
|
w := AWorksheet.ReadDefaultColWidth(suChars);
|
||||||
w := FWorkbook.ConvertUnits(col^.Width, FWorkbook.Units, suChars)
|
if lCol <> nil then begin
|
||||||
else
|
if lCol^.ColWidthType = cwtCustom then begin
|
||||||
w := AWorksheet.ReadDefaultColWidth(suChars);
|
w := FWorkbook.ConvertUnits(lCol^.Width, FWorkbook.Units, suChars);
|
||||||
|
customWidth := 'customWidth="1" ';
|
||||||
|
end;
|
||||||
|
if lCol^.FormatIndex > 0 then customStyle := Format('style="%d" ', [lCol^.FormatIndex]);
|
||||||
|
end;
|
||||||
AppendToStream(AStream, Format(
|
AppendToStream(AStream, Format(
|
||||||
'<col min="%d" max="%d" width="%.2f" customWidth="1" />',
|
'<col min="%d" max="%d" width="%.2f" %s%s />',
|
||||||
[c+1, c+1, w], FPointSeparatorSettings)
|
[c+1, c+1, w, customWidth, customStyle], FPointSeparatorSettings)
|
||||||
);
|
);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user