diff --git a/components/fpspreadsheet/tests/formattests.pas b/components/fpspreadsheet/tests/formattests.pas index 8e66d1381..ed345dc99 100644 --- a/components/fpspreadsheet/tests/formattests.pas +++ b/components/fpspreadsheet/tests/formattests.pas @@ -1105,11 +1105,7 @@ begin try MyWorkSheet:= MyWorkBook.AddWorksheet(ColWidthSheet); for Col := Low(SollColWidths) to High(SollColWidths) do - begin - lCol.Width := SollColWidths[Col]; - //MyWorksheet.WriteNumber(0, Col, 1); - MyWorksheet.WriteColInfo(Col, lCol); - end; + MyWorksheet.WriteColWidth(Col, SollColWidths[Col], suChars); if AFormat = sfOpenDocument then // In ODS empty columns are ignored due to a workaround for a // LO/OO import error for xlsx files. --> add dummy cells @@ -1136,7 +1132,7 @@ begin lpCol := MyWorksheet.GetCol(Col); if lpCol = nil then fail('Error in test code. Failed to return saved column width'); - ActualColWidth := lpCol^.Width; + ActualColWidth := MyWorkbook.ConvertUnits(lpCol^.Width, MyWorkbook.Units, suChars); if abs(SollColWidths[Col] - ActualColWidth) > 1E-2 then // take rounding errors into account CheckEquals(SollColWidths[Col], ActualColWidth, 'Test saved colwidth mismatch, column '+ColNotation(MyWorkSheet,Col)); diff --git a/components/fpspreadsheet/xlsxooxml.pas b/components/fpspreadsheet/xlsxooxml.pas index 10858b2c7..a8b864893 100755 --- a/components/fpspreadsheet/xlsxooxml.pas +++ b/components/fpspreadsheet/xlsxooxml.pas @@ -2970,7 +2970,7 @@ var lCell: TCell; styleCell: PCell; cell: PCell; - rh: String; + s: String; begin AppendToStream(AStream, ''); @@ -2983,15 +2983,18 @@ begin then begin for r := 0 to r2 do begin row := AWorksheet.FindRow(r); + s := ''; if row <> nil then begin - rh := Format(' ht="%.2f"', + s := s + Format(' ht="%.2f"', [FWorkbook.ConvertUnits(row^.Height, FWorkbook.Units, suPoints)], FPointSeparatorSettings); - if row^.RowHeightType = rhtCustom then rh := rh + ' customHeight="1"'; - end else - rh := ''; + if row^.RowHeightType = rhtCustom then + s := s + ' customHeight="1"'; + if row^.FormatIndex > 0 then + s := s + Format(' s="%d" customFormat="1"', [row^.FormatIndex]); + end; AppendToStream(AStream, Format( - '', [r+1, AWorksheet.VirtualColCount, rh])); + '', [r+1, AWorksheet.VirtualColCount, s])); for c := 0 to c2 do begin lCell.Row := r; // to silence a compiler hint InitCell(lCell); @@ -3041,24 +3044,28 @@ begin begin // The cells need to be written in order, row by row, cell by cell for r := r1 to r2 do begin - // If the row has a custom height add this value to the specification + // If the row has a custom or auto height and/or custom format + // then add them to the specification row := AWorksheet.FindRow(r); + s := ''; if row <> nil then begin - rh := Format(' ht="%.2f"', + s := s + Format(' ht="%.2f"', [FWorkbook.ConvertUnits(row^.Height, FWorkbook.Units, suPoints)], FPointSeparatorSettings); - if row^.RowHeightType = rhtCustom then rh := rh + ' customHeight="1"'; - end else - rh := ''; + if row^.RowHeightType = rhtCustom then + s := s + ' customHeight="1"'; + if row^.FormatIndex > 0 then + s := s + Format(' s="%d" customFormat="1"', [row^.FormatIndex]); + end; AppendToStream(AStream, Format( - '', [r+1, c1+1, c2+1, rh])); + '', [r+1, c1+1, c2+1, s])); // Write cells belonging to this row. - { // Strange: the RowEnumerator is very slow here... ?! + { + // Strange: the RowEnumerator is very slow here... ?! for cell in AWorksheet.Cells.GetRowEnumerator(r) do WriteCellToStream(AStream, cell); } - for c := c1 to c2 do begin cell := AWorksheet.FindCell(r, c); if Assigned(cell) then