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
|
||||
rec: TColRecord;
|
||||
w: Integer;
|
||||
width: Single;
|
||||
begin
|
||||
if Assigned(ACol) then
|
||||
begin
|
||||
@ -3256,7 +3257,13 @@ begin
|
||||
rec.EndCol := WordToLE(ACol^.Col);
|
||||
|
||||
{ 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.XFIndex := WordToLE(FindXFIndex(ACol^.FormatIndex));// Index of XF record
|
||||
|
@ -2526,23 +2526,32 @@ end;
|
||||
|
||||
procedure TsSpreadOOXMLWriter.WriteCols(AStream: TStream; AWorksheet: TsWorksheet);
|
||||
var
|
||||
col: PCol;
|
||||
lCol: PCol;
|
||||
c: Integer;
|
||||
w: Single;
|
||||
customWidth: String;
|
||||
customStyle: String;
|
||||
begin
|
||||
AppendToStream(AStream,
|
||||
'<cols>');
|
||||
|
||||
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.
|
||||
if col <> nil then
|
||||
w := FWorkbook.ConvertUnits(col^.Width, FWorkbook.Units, suChars)
|
||||
else
|
||||
w := AWorksheet.ReadDefaultColWidth(suChars);
|
||||
w := AWorksheet.ReadDefaultColWidth(suChars);
|
||||
if lCol <> nil then begin
|
||||
if lCol^.ColWidthType = cwtCustom then begin
|
||||
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(
|
||||
'<col min="%d" max="%d" width="%.2f" customWidth="1" />',
|
||||
[c+1, c+1, w], FPointSeparatorSettings)
|
||||
'<col min="%d" max="%d" width="%.2f" %s%s />',
|
||||
[c+1, c+1, w, customWidth, customStyle], FPointSeparatorSettings)
|
||||
);
|
||||
end;
|
||||
|
||||
|
Reference in New Issue
Block a user