📄 frxexportodf.pas
字号:
end;
end;
with XML.Root.Add do
begin
Name := 'office:master-styles';
with Add do
begin
Name := 'style:master-page';
Prop['style:name'] := 'PageDef';
Prop['style:page-layout-name'] := 'pm1';
with Add do
begin
Name := 'style:header';
Prop['style:display'] := 'false';
end;
with Add do
begin
Name := 'style:footer';
Prop['style:display'] := 'false';
end;
end;
end;
XML.SaveToFile(FTempFolder + 'styles.xml');
finally
XML.Free;
end;
XML := TfrxXMLDocument.Create;
try
XML.AutoIndent := True;
XML.Root.Name := 'office:document-content';
OdfMakeHeader(XML.Root);
with XML.Root.Add do
Name := 'office:scripts';
// font styles
FList := TStringList.Create;
try
FList.Sorted := True;
for i := 0 to FMatrix.StylesCount - 1 do
begin
Style := FMatrix.GetStyleById(i);
if (Style.Font <> nil) and (FList.IndexOf(Style.Font.Name) = -1) then
FList.Add(Style.Font.Name);
end;
with XML.Root.Add do
begin
Name := 'office:font-face-decls';
for i := 0 to FList.Count - 1 do
begin
with Add do
begin
Name := 'style:font-face';
Prop['style:name'] := FList[i];
Prop['svg:font-family'] := ''' + FList[i] + ''';
Prop['style:font-pitch'] := 'variable';
end;
end;
end;
finally
FList.Free;
end;
with XML.Root.Add do
begin
Name := 'office:automatic-styles';
// columns styles
FList := TStringList.Create;
try
FList.Sorted := True;
for i := 1 to FMatrix.Width - 1 do
begin
d := (FMatrix.GetXPosById(i) - FMatrix.GetXPosById(i - 1)) / odfDivider;
s := frFloat2Str(d, 3);
if FList.IndexOf(s) = -1 then
FList.Add(s);
end;
for i := 0 to FList.Count - 1 do
begin
with Add do
begin
Name := 'style:style';
Prop['style:name'] := 'co' + FList[i];
Prop['style:family'] := 'table-column';
with Add do
begin
Name := 'style:table-column-properties';
Prop['fo:break-before'] := 'auto';
Prop['style:column-width'] := FList[i] + 'cm';
end;
end;
end;
finally
FList.Free;
end;
// rows styles
FList := TStringList.Create;
try
FList.Sorted := True;
for i := 0 to FMatrix.Height - 2 do
begin
d := (FMatrix.GetYPosById(i + 1) - FMatrix.GetYPosById(i)) / odfDivider;
s := frFloat2Str(d, 3);
if FList.IndexOf(s) = -1 then
FList.Add(s);
end;
for i := 0 to FList.Count - 1 do
begin
with Add do
begin
Name := 'style:style';
Prop['style:name'] := 'ro' + FList[i];
Prop['style:family'] := 'table-row';
with Add do
begin
Name := 'style:table-row-properties';
Prop['fo:break-before'] := 'auto';
Prop['style:row-height'] := FList[i] + 'cm';
end;
end;
end;
with Add do
begin
Name := 'style:style';
Prop['style:name'] := 'ro_breaked';
Prop['style:family'] := 'table-row';
with Add do
begin
Name := 'style:table-row-properties';
Prop['fo:break-before'] := 'page';
Prop['style:row-height'] := '0.001cm';
end;
end;
finally
FList.Free;
end;
// table style
with Add do
begin
Name := 'style:style';
Prop['style:name'] := 'ta1';
Prop['style:family'] := 'table';
Prop['style:master-page-name'] := 'PageDef';
with Add do
begin
Name := 'style:table-properties';
Prop['table:display'] := 'true';
Prop['style:writing-mode'] := 'lr-tb'; /// RTL - LTR?
end;
end;
// cells styles
with Add do
begin
Name := 'style:style';
Prop['style:name'] := 'ceb';
Prop['style:family'] := 'table-cell';
Prop['style:display'] := 'false';
end;
for i := 0 to FMatrix.StylesCount - 1 do
begin
Style := FMatrix.GetStyleById(i);
with Add do
begin
Name := 'style:style';
Prop['style:name'] := 'ce' + IntToStr(i);
Prop['style:family'] := 'table-cell';
Prop['style:parent-style-name'] := 'Default';
if FExportType <> 'text' then
begin
with Add do
begin
Name := 'style:text-properties';
Prop['style:font-name'] := Style.Font.Name;
Prop['fo:font-size'] := IntToStr(Style.Font.Size) + 'pt';
if fsUnderline in Style.Font.Style then
begin
Prop['style:text-underline-style'] := 'solid';
Prop['style:text-underline-width'] := 'auto';
Prop['style:text-underline-color'] := 'font-color';
end;
if fsItalic in Style.Font.Style then
Prop['fo:font-style'] := 'italic';
if fsBold in Style.Font.Style then
Prop['fo:font-weight'] := 'bold';
Prop['fo:color'] := HTMLRGBColor(Style.Font.Color);
end;
with Add do
begin
Name := 'style:paragraph-properties';
if Style.HAlign = haLeft then
Prop['fo:text-align'] := 'start';
if Style.HAlign = haCenter then
Prop['fo:text-align'] := 'center';
if Style.HAlign = haRight then
Prop['fo:text-align'] := 'end';
if Style.GapX <> 0 then
begin
Prop['fo:margin-left'] := frFloat2Str(Style.GapX / odfDivider, 3) + 'cm';
Prop['fo:margin-right'] := Prop['fo:margin-left'];
end;
end;
end;
with Add do
begin
Name := 'style:table-cell-properties';
Prop['fo:background-color'] := HTMLRGBColor(Style.Color);
Prop['style:repeat-content'] := 'false';
if Style.Rotation > 0 then
begin
Prop['style:rotation-angle'] := IntToStr(Style.Rotation);
Prop['style:rotation-align'] := 'none';
end;
if Style.VAlign = vaCenter then
Prop['style:vertical-align'] := 'middle';
if Style.VAlign = vaTop then
Prop['style:vertical-align'] := 'top';
if Style.VAlign = vaBottom then
Prop['style:vertical-align'] := 'bottom';
if (ftLeft in Style.FrameTyp) then
Prop['fo:border-left'] := frFloat2Str(Style.FrameWidth / odfDivider, 3) + 'cm ' + OdfGetFrameName(Style.FrameStyle) + ' ' + HTMLRGBColor(Style.FrameColor);
if (ftRight in Style.FrameTyp) then
Prop['fo:border-right'] := frFloat2Str(Style.FrameWidth / odfDivider, 3) + 'cm ' + OdfGetFrameName(Style.FrameStyle) + ' ' + HTMLRGBColor(Style.FrameColor);
if (ftTop in Style.FrameTyp) then
Prop['fo:border-top'] := frFloat2Str(Style.FrameWidth / odfDivider, 3) + 'cm ' + OdfGetFrameName(Style.FrameStyle) + ' ' + HTMLRGBColor(Style.FrameColor);
if (ftBottom in Style.FrameTyp) then
Prop['fo:border-bottom'] := frFloat2Str(Style.FrameWidth / odfDivider, 3) + 'cm ' + OdfGetFrameName(Style.FrameStyle) + ' ' + HTMLRGBColor(Style.FrameColor);
end;
end;
end;
if FExportType = 'text' then
begin
// text styles
with Add do
begin
Name := 'style:style';
Prop['style:name'] := 'pb';
Prop['style:family'] := 'paragraph';
Prop['style:display'] := 'false';
end;
for i := 0 to FMatrix.StylesCount - 1 do
begin
Style := FMatrix.GetStyleById(i);
with Add do
begin
Name := 'style:style';
Prop['style:name'] := 'p' + IntToStr(i);
Prop['style:family'] := 'paragraph';
Prop['style:parent-style-name'] := 'Default';
with Add do
begin
Name := 'style:text-properties';
Prop['style:font-name'] := Style.Font.Name;
Prop['fo:font-size'] := IntToStr(Style.Font.Size) + 'pt';
if fsUnderline in Style.Font.Style then
begin
Prop['style:text-underline-style'] := 'solid';
Prop['style:text-underline-width'] := 'auto';
Prop['style:text-underline-color'] := 'font-color';
end;
if fsItalic in Style.Font.Style then
Prop['fo:font-style'] := 'italic';
if fsBold in Style.Font.Style then
Prop['fo:font-weight'] := 'bold';
Prop['fo:color'] := HTMLRGBColor(Style.Font.Color);
end;
with Add do
begin
Name := 'style:paragraph-properties';
if Style.HAlign = haLeft then
Prop['fo:text-align'] := 'start';
if Style.HAlign = haCenter then
Prop['fo:text-align'] := 'center';
if Style.HAlign = haRight then
Prop['fo:text-align'] := 'end';
if Style.GapX <> 0 then
begin
Prop['fo:margin-left'] := frFloat2Str(Style.GapX / odfDivider, 3) + 'cm';
Prop['fo:margin-right'] := Prop['fo:margin-left'];
end;
end;
end;
end;
end;
// pic style
with Add do
begin
Name := 'style:style';
Prop['style:name'] := 'gr1';
Prop['style:family'] := 'graphic';
with Add do
begin
Name := 'style:graphic-properties';
Prop['draw:stroke'] := 'none';
Prop['draw:fill'] := 'none';
Prop['draw:textarea-horizontal-align'] := 'left';
Prop['draw:textarea-vertical-align'] := 'top';
Prop['draw:color-mode'] := 'standard';
Prop['draw:luminance'] := '0%';
Prop['draw:contrast'] := '0%';
Prop['draw:gamma'] := '100%';
Prop['draw:red'] := '0%';
Prop['draw:green'] := '0%';
Prop['draw:blue'] := '0%';
Prop['fo:clip'] := 'rect(0cm 0cm 0cm 0cm)';
Prop['draw:image-opacity'] := '100%';
Prop['style:mirror'] := 'none';
end;
end;
end;
// BODY
with XML.Root.Add do
begin
Name := 'office:body';
with Add do
begin
Name := 'office:spreadsheet';
with Add do
begin
Name := 'table:table';
Prop['table:name'] := 'Table';
Prop['table:style-name'] := 'ta1';
Prop['table:print'] := 'false';
for x := 1 to FMatrix.Width - 1 do
with Add do
begin
Name := 'table:table-column';
d := (FMatrix.GetXPosById(x) - FMatrix.GetXPosById(x - 1)) / odfDivider;
s := frFloat2Str(d, 3);
Prop['table:style-name'] := 'co' + s;
end;
Page := 0;
for y := 0 to FMatrix.Height - 2 do
begin
if ShowProgress then
begin
FProgress.Tick;
if FProgress.Terminated then
break;
end;
if FMatrix.PagesCount > Page then
if FMatrix.GetYPosById(y) >= FMatrix.GetPageBreak(Page) then
begin
Inc(Page);
if FExportPageBreaks then
with Add do
begin
Name := 'table:table-row';
Prop['table:style-name'] := 'ro_breaked';
end;
// continue;
end;
with Add do
begin
Name := 'table:table-row';
d := (FMatrix.GetYPosById(y + 1) - FMatrix.GetYPosById(y)) / odfDivider;
s := frFloat2Str(d, 3);
Prop['table:style-name'] := 'ro' + s;
for x := 0 to FMatrix.Width - 1 do
begin
i := FMatrix.GetCell(x, y);
with Add do
begin
if i <> -1 then
begin
Obj := FMatrix.GetObjectById(i);
if Obj.Counter = 0 then
begin
Name := 'table:table-cell';
Obj.Counter := 1;
FMatrix.GetObjectPos(i, fx, fy, dx, dy);
Prop['table:style-name'] := 'ce' + IntToStr(Obj.StyleIndex);
if dx > 1 then
Prop['table:number-columns-spanned'] := IntToStr(dx);
if dy > 1 then
Prop['table:number-rows-spanned'] := IntToStr(dy);
// text
if Obj.IsText then
begin
// s := UTF8Encode(OdfPrepareString(Obj.Memo.Text));
// added from
s := OdfPrepareString(Obj.Memo.Text);
if Obj.Style.FDisplayFormat.Kind = fkNumeric then
begin
s2 := '';
for l := 1 to length(s) do
if ((s[l] >= '0') and (s[l] <= '9')) or (s[l] = '-') then
s2 := s2 + s[l]
else
if (Copy(s, l, 1) = DecimalSeparator) or (Copy(s, l, 1) = Obj.Style.DisplayFormat.DecimalSeparator) then
s2 := s2 + '.';
Prop['office:value-type'] := 'float';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -