fpspreadsheet: Write defaultrowheight and defaultcolwidth for Excel formats (don't know how ods stores them...)

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4543 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-03-11 22:42:13 +00:00
parent 345f1c6818
commit d5fb9128ef
6 changed files with 121 additions and 1 deletions

View File

@ -184,6 +184,7 @@ type
function WriteBorderStyleXMLAsString(const AFormat: TsCellFormat): String;
function WriteCommentXMLAsString(AComment: String): String;
function WriteDefaultFontXMLAsString: String;
function WriteDefaultGraphicStyleXMLAsString: String; overload;
function WriteFontStyleXMLAsString(const AFormat: TsCellFormat): String; overload;
function WriteFontStyleXMLAsString(AFont: TsFont): String; overload;
function WriteHeaderFooterFontXMLAsString(AFont: TsHeaderFooterFont): String;
@ -4335,6 +4336,11 @@ begin
'<style:style style:name="Default" style:family="table-cell">',
WriteDefaultFontXMLAsString,
'</style:style>');
if FWorkbook.GetEmbeddedStreamCount > 0 then
AppendToStream(FSStyles,
'<style:default-style style:family="graphic">',
WriteDefaultGraphicStyleXMLAsString,
'</style:default-style>');
AppendToStream(FSStyles,
'</office:styles>');
@ -5496,6 +5502,28 @@ begin
);
end;
function TsSpreadOpenDocWriter.WriteDefaultGraphicStyleXMLAsString: String;
begin
Result :=
'<style:graphic-properties svg:stroke-color="#3465a4" '+
'draw:fill-color="#729fcf" fo:wrap-option="no-wrap" '+
'draw:shadow-offset-x="3mm" draw:shadow-offset-y="3mm" />' +
'<style:paragraph-properties style:text-autospace="ideograph-alpha" '+
'style:punctuation-wrap="simple" style:line-break="strict" '+
'style:writing-mode="page" style:font-independent-line-spacing="false">'+
'<style:tab-stops />'+
'</style:paragraph-properties>'+
'<style:text-properties style:use-window-font-color="true" '+
'fo:font-family="''Liberation Serif''" style:font-family-generic="roman" '+
'style:font-pitch="variable" fo:font-size="12pt" ' +
//'fo:language="de" fo:country="DE" '+
'style:letter-kerning="true" '+
'style:font-name-asian="Segoe UI" style:font-size-asian="12pt" '+
'style:language-asian="zh" style:country-asian="CN" '+
'style:font-name-complex="Tahoma" style:font-size-complex="12pt" '+
'style:language-complex="hi" style:country-complex="IN" />';
end;
procedure TsSpreadOpenDocWriter.WriteError(AStream: TStream;
const ARow, ACol: Cardinal; const AValue: TsErrorValue; ACell: PCell);
var

View File

@ -106,6 +106,7 @@ type
procedure WriteBool(AStream: TStream; const ARow, ACol: Cardinal;
const AValue: Boolean; ACell: PCell); override;
procedure WriteCodePage(AStream: TStream; ACodePage: String); override;
procedure WriteDefaultRowHeight(AStream: TStream; AWorksheet: TsWorksheet);
procedure WriteError(AStream: TStream; const ARow, ACol: Cardinal;
const AValue: TsErrorValue; ACell: PCell); override;
procedure WriteFORMAT(AStream: TStream; ANumFormatStr: String;
@ -179,7 +180,7 @@ const
INT_EXCEL_ID_FORMAT = $001E;
INT_EXCEL_ID_FORMATCOUNT = $001F;
INT_EXCEL_ID_COLWIDTH = $0024;
INT_EXCEL_ID_DEFROWHEIGHT = 00025;
INT_EXCEL_ID_DEFROWHEIGHT = $0025;
INT_EXCEL_ID_WINDOW2 = $003E;
INT_EXCEL_ID_XF = $0043;
INT_EXCEL_ID_IXFE = $0044;
@ -1310,6 +1311,7 @@ begin
WriteCodePage(AStream, FCodePage);
WritePrintHeaders(AStream);
WritePrintGridLines(AStream);
WriteDefaultRowHeight(AStream, FWorksheet);
WriteFonts(AStream);
// Page settings block
@ -1323,6 +1325,8 @@ begin
WriteFormatCount(AStream);
WriteNumFormats(AStream);
WriteXFRecords(AStream);
WriteDefaultColWidth(AStream, FWorksheet);
WriteColWidths(AStream);
WriteDimensions(AStream, FWorksheet);
WriteRows(AStream, FWorksheet);
@ -1760,6 +1764,27 @@ begin
AStream.WriteBuffer(rec, SizeOf(rec));
end;
{@@ ----------------------------------------------------------------------------
Writes an Excel 2 DEFAULTROWHEIGHT record
Specifies the default height and default flags for rows that do not have a
corresponding ROW record
-------------------------------------------------------------------------------}
procedure TsSpreadBIFF2Writer.WriteDefaultRowHeight(AStream: TStream;
AWorksheet: TsWorksheet);
var
h: Single;
begin
{ BIFF record header }
WriteBIFFHeader(AStream, INT_EXCEL_ID_DEFROWHEIGHT, 2);
{ Default height for unused rows, in twips = 1/20 of a point
Bits 0-14: Default height for unused rows, in twips
Bit 15 = 1: Row height not changed manually }
h := (AWorksheet.DefaultRowHeight + ROW_HEIGHT_CORRECTION) * FWorkbook.GetDefaultFontSize;
AStream.WriteWord(WordToLE(PtsToTwips(h)));
end;
{@@ ----------------------------------------------------------------------------
Writes an Excel 2 ERROR cell record.
-------------------------------------------------------------------------------}

View File

@ -1144,6 +1144,7 @@ begin
WriteIndex(AStream);
WritePrintHeaders(AStream);
WritePrintGridLines(AStream);
WriteDefaultRowHeight(AStream, FWorksheet);
WriteSheetPR(AStream);
// Page settings block
@ -1157,6 +1158,7 @@ begin
WriteMargin(AStream, 3); // 3 = bottom margin
WritePageSetup(AStream);
WriteDefaultColWidth(AStream, FWorksheet);
WriteColInfos(AStream, FWorksheet);
WriteDimensions(AStream, FWorksheet);
WriteWindow2(AStream, FWorksheet);

View File

@ -2121,6 +2121,7 @@ begin
WriteIndex(AStream);
WritePrintHeaders(AStream);
WritePrintGridLines(AStream);
WriteDefaultRowHeight(AStream, FWorksheet);
WriteSheetPR(AStream);
// Page setting block
@ -2134,6 +2135,7 @@ begin
WriteMargin(AStream, 3); // 3 = bottom margin
WritePageSetup(AStream);
WriteDefaultColWidth(AStream, FWorksheet);
WriteColInfos(AStream, FWorksheet);
WriteDimensions(AStream, FWorksheet);
//WriteRowAndCellBlock(AStream, sheet);

View File

@ -530,6 +530,10 @@ type
// Writes out a TIME/DATE/TIMETIME
procedure WriteDateTime(AStream: TStream; const ARow, ACol: Cardinal;
const AValue: TDateTime; ACell: PCell); override;
// Writes out a DEFCOLWIDTH record
procedure WriteDefaultColWidth(AStream: TStream; AWorksheet: TsWorksheet);
// Writes out a DEFAULTROWHEIGHT record
procedure WriteDefaultRowHeight(AStream: TStream; AWorksheet: TsWorksheet);
// Writes out DEFINEDNAMES records
procedure WriteDefinedName(AStream: TStream; AWorksheet: TsWorksheet;
const AName: String; AIndexToREF: Word); virtual;
@ -3296,6 +3300,50 @@ begin
WriteNumber(AStream, ARow, ACol, ExcelDateSerial, ACell);
end;
{@@ ----------------------------------------------------------------------------
Writes a DEFCOLWIDTH record.
Specifies the default column width for columns that do not have a
specific width set using the records COLWIDTH (BIFF2), COLINFO (BIFF3-BIFF8),
or STANDARDWIDTH.
Valud for BIFF2-BIFF8.
-------------------------------------------------------------------------------}
procedure TsSpreadBIFFWriter.WriteDefaultColWidth(AStream: TStream;
AWorksheet: TsWorksheet);
begin
{ BIFF record header }
WriteBIFFHeader(AStream, INT_EXCEL_ID_DEFCOLWIDTH, 2);
{ Column width in characters, using the width of the zero character
from default font (first FONT record in the file). }
AStream.WriteWord(round(FWorksheet.DefaultColWidth));
end;
{@@ ----------------------------------------------------------------------------
Writes a DEFAULTROWHEIGHT record
Specifies the default height and default flags for rows that do not have a
corresponding ROW record
Valid for BIFF3-BIFF8.
-------------------------------------------------------------------------------}
procedure TsSpreadBIFFWriter.WriteDefaultRowHeight(AStream: TStream;
AWorksheet: TsWorksheet);
var
h: Single;
begin
{ BIFF record header }
WriteBIFFHeader(AStream, INT_EXCEL_ID_DEFROWHEIGHT, 4);
{ Options:
Bit 1 = Row height and default font height do not match
Bit 2 = Row is hidden
Bit 4 = Additional space above the row
Bit 8 = Additional space below the row }
AStream.WriteWord(WordToLE($0001));
{ Default height for unused rows, in twips = 1/20 of a point }
h := (AWorksheet.DefaultRowHeight + ROW_HEIGHT_CORRECTION) * FWorkbook.GetDefaultFontSize;
AStream.WriteWord(WordToLE(PtsToTwips(h)));
end;
procedure TsSpreadBIFFWriter.WriteDefinedName(AStream: TStream;
AWorksheet: TsWorksheet; const AName: String; AIndexToREF: Word);
begin

View File

@ -148,6 +148,7 @@ type
procedure WritePageSetup(AStream: TStream; AWorksheet: TsWorksheet);
procedure WritePrintOptions(AStream: TStream; AWorksheet: TsWorksheet);
procedure WriteSheetData(AStream: TStream; AWorksheet: TsWorksheet);
procedure WriteSheetFormatPr(AStream: TStream; AWorksheet: TsWorksheet);
procedure WriteSheetPr(AStream: TStream; AWorksheet: TsWorksheet);
procedure WriteSheetViews(AStream: TStream; AWorksheet: TsWorksheet);
procedure WriteStyleList(AStream: TStream; ANodeName: String);
@ -3020,6 +3021,19 @@ begin
'</sheetData>');
end;
procedure TsSpreadOOXMLWriter.WriteSheetFormatPr(AStream: TStream;
AWorksheet: TsWorksheet);
var
w, h: Single;
begin
w := AWorksheet.DefaultColWidth;
h := (AWorksheet.DefaultRowHeight + ROW_HEIGHT_CORRECTION) * Workbook.GetDefaultFontSize;
AppendToStream(AStream, Format(
'<sheetFormatPr baseColWidth="%g" defaultRowHeight="%g" customHeight="true" />',
[w, h],
FPointSeparatorSettings));
end;
procedure TsSpreadOOXMLWriter.WriteSheetPr(AStream: TStream; AWorksheet: TsWorksheet);
var
s: String;
@ -4194,6 +4208,7 @@ begin
WriteSheetPr(FSSheets[FCurSheetNum], AWorksheet);
WriteDimension(FSSheets[FCurSheetNum], AWorksheet);
WriteSheetViews(FSSheets[FCurSheetNum], AWorksheet);
WriteSheetFormatPr(FSSheets[FCurSheetNum], AWorksheet);
WriteCols(FSSheets[FCurSheetNum], AWorksheet);
WriteSheetData(FSSheets[FCurSheetNum], AWorksheet);
WriteMergedCells(FSSheets[FCurSheetNum], AWorksheet);