📄 baseodfclass4.pas
字号:
WriteSpecificNode(1013, '', [], []);
WriteSpecificNode(1012, '', [], []);
WriteSpecificNode(108, '', [], []);
finally
FExportWriter.Free;
end;
finally
FExportStream.Free;
end;
end;
procedure TBaseODFFile.MakeAll;
begin
if FileName = '' then
raise Exception.Create(sFileNameNotDefined);
if not CreateCommonStructure then
raise Exception.Create(sStructureCreateFailed);
if TypeConvert = -1 then
raise Exception.Create(sConvertWrong);
//meta.xml form
try
FExportStream := TFileStream.Create(TempPath + '\meta.xml', fmCreate);
try
FExportWriter := TQXMLWriter.Create(FExportStream);
WriteSpecificNode(1, '', [], []);
WriteSpecificNode(2, '', [], []);
finally
FExportWriter.Free;
end;
finally
FExportStream.Free;
end;
//manifest.xml of both types
try
FExportStream := TFileStream.Create(TempPath + '\META-INF\manifest.xml',
fmCreate);
try
FExportWriter := TQXMLWriter.Create(FExportStream);
WriteSpecificNode(1, '', [], []);
if (TypeConvert = 0) then
WriteSpecificNode(204, '', [], [])
else
WriteSpecificNode(104, '', [], []);
finally
FExportWriter.Free;
end;
finally
FExportStream.Free;
end;
end;
procedure TBaseODFFile.Renew;
begin
DeleteTempFolder;
TypeConvert := -1;
end;
procedure TBaseODFFile.OpenStream(FName: string);
begin
FExportStream := TFileStream.Create(TempPath + '\' + FName, fmCreate);
end;
procedure TBaseODFFile.OpenWriter;
begin
FExportWriter := TQXMLWriter.Create(FExportStream);
end;
procedure TBaseODFFile.CloseStream;
begin
FExportStream.Free;
end;
procedure TBaseODFFile.CloseWriter;
begin
FExportWriter.Free;
end;
procedure TBaseODFFile.CheckStatus;
begin
if not assigned(FExportStream) or not assigned(FExportWriter) then
raise Exception.Create('Could not initialize temporary files');
end;
procedure TBaseODFFile.MergeContent(Name: WideString;
FileNames: array of WideString);
var
Stream1, Stream2: TStream;
i: Integer;
begin
Stream1 := TFileStream.Create(TempPath + '\' + Name, fmCreate);
for i := 0 to length(FileNames) - 1 do
begin
Stream2 := TFileStream.Create(TempPath + '\' + FileNames[i], fmOpenRead);
Stream1.CopyFrom(Stream2, 0);
Stream2.Free;
end;
Stream1.Free;
end;
procedure TBaseODFFile.DeleteList(FileNames: array of WideString);
var
i: Integer;
begin
for i := 0 to length(FileNames) - 1 do
begin
if not FileExists(TempPath + '\' + FileNames[i]) then
raise Exception.Create('Temporary file not found')
else
if not SysUtils.DeleteFile(TempPath + '\' + FileNames[i]) then
raise Exception.Create('Could not delete temporary file');
end;
end;
{ TODSParagraphStyle }
procedure TODSParagraphStyle.Assign(Source: TPersistent);
begin
if Source is TODSParagraphStyle then
begin
Font := (Source as TODSParagraphStyle).Font;
BackgroundColor := (Source as TODSParagraphStyle).BackgroundColor;
AllowBackground := (Source as TODSParagraphStyle).AllowBackground;
Alignment := (Source as TODSParagraphStyle).Alignment;
Exit;
end;
inherited;
end;
constructor TODSParagraphStyle.Create(Collection: TCollection);
begin
inherited;
FFont := TFont.Create;
SetDefault;
end;
destructor TODSParagraphStyle.Destroy;
begin
FFont.Free;
inherited;
end;
procedure TODSParagraphStyle.LoadFromIniFile(IniFile: TQIniFile;
const Section: string);
begin
with IniFile do begin
Font.Name := ReadString(Section, S_ODF_FontName, 'arial');
Font.Size := ReadInteger(Section, S_ODF_FontSize, 10);
Font.Color := ReadInteger(Section, S_ODF_FontColor, clBlack);
if ReadBool(Section, S_ODF_FontBold, false)
then Font.Style := Font.Style + [fsBold]
else Font.Style := Font.Style - [fsBold];
if ReadBool(Section, S_ODF_FontItalic, false)
then Font.Style := Font.Style + [fsItalic]
else Font.Style := Font.Style - [fsItalic];
if ReadBool(Section, S_ODF_FontStrikeOut, false)
then Font.Style := Font.Style + [fsStrikeOut]
else Font.Style := Font.Style - [fsStrikeOut];
if ReadBool(Section, S_ODF_FontUnderline, false)
then Font.Style := Font.Style + [fsUnderline]
else Font.Style := Font.Style - [fsUnderline];
AllowBackground := ReadBool(Section, S_ODF_AllowBackground, true);
BackgroundColor := ReadInteger(Section, S_ODF_BackgroundColor, clWhite);
Alignment := TODFTextAlignment(ReadInteger(Section, S_ODF_HorAlignment,
Integer(taODFLeft)));
end;
end;
procedure TODSParagraphStyle.SaveToIniFile(IniFile: TQIniFile;
const Section: string);
begin
with IniFile do begin
WriteString(Section, S_ODF_FontName, Font.Name);
WriteInteger(Section, S_ODF_FontSize, Font.Size);
WriteInteger(Section, S_ODF_FontColor, Font.Color);
if fsBold in Font.Style then
WriteBool(Section, S_ODF_FontBold, true)
else
WriteBool(Section, S_ODF_FontBold, false);
if fsItalic in Font.Style then
WriteBool(Section, S_ODF_FontItalic, true)
else
WriteBool(Section, S_ODF_FontItalic, false);
if fsStrikeOut in Font.Style then
WriteBool(Section, S_ODF_FontStrikeOut, true)
else
WriteBool(Section, S_ODF_FontStrikeOut, false);
if fsUnderline in Font.Style then
WriteBool(Section, S_ODF_FontUnderline, true)
else
WriteBool(Section, S_ODF_FontUnderline, false);
WriteBool(Section, S_ODF_AllowBackground, AllowBackground);
WriteInteger(Section, S_ODF_BackgroundColor, BackgroundColor);
WriteInteger(Section, S_ODF_HorAlignment, Integer(Alignment));
end;
end;
procedure TODSParagraphStyle.SetDefault;
begin
FFont.Name := 'Arial';
FFont.Size := 10;
FFont.Style := [];
FFont.Color := clBlack;
FBackgroundColor := clWhite;
FAllowBackground := true;
FAlignment := taODFLeft;
end;
procedure TODSParagraphStyle.SetFont(const Value: TFont);
begin
FFont.Assign(Value);
end;
{ TODTParagraphStyle }
procedure TODTParagraphStyle.Assign(Source: TPersistent);
begin
if Source is TODTParagraphStyle then
begin
HighlightColor := (Source as TODTParagraphStyle).HighlightColor;
AllowHighlight := (Source as TODTParagraphStyle).AllowHighlight;
inherited Assign(Source as TODSParagraphStyle);
Exit;
end;
inherited;
end;
constructor TODTParagraphStyle.Create(Collection: TCollection);
begin
inherited Create(Collection);
end;
destructor TODTParagraphStyle.Destroy;
begin
inherited;
end;
procedure TODTParagraphStyle.LoadFromIniFile(IniFile: TQIniFile;
const Section: string);
begin
inherited;
with IniFile do begin
AllowHighlight := ReadBool(Section, S_ODT_AllowHighlight, false);
HighlightColor := ReadInteger(Section, S_ODT_HighlightColor, clWhite);
end;
end;
procedure TODTParagraphStyle.SaveToIniFile(IniFile: TQIniFile;
const Section: string);
begin
inherited;
with IniFile do begin
WriteBool(Section, S_ODT_AllowHighlight, AllowHighlight);
WriteInteger(Section, S_ODT_HighlightColor, HighlightColor);
end;
end;
procedure TODTParagraphStyle.SetDefault;
begin
inherited;
FHighlightColor := clWhite;
FAllowHighlight := false;
end;
{ TODTStylesList }
function TODTStylesList.Add: TODTCellParagraphStyle;
begin
Result := TODTCellParagraphStyle(inherited Add);
end;
constructor TODTStylesList.Create(Holder: TPersistent);
begin
inherited Create(TODTCellParagraphStyle);
FHolder := Holder;
end;
function TODTStylesList.GetItem(Index: Integer): TODTCellParagraphStyle;
begin
Result := inherited GetItem(Index) as TODTCellParagraphStyle;
end;
function TODTStylesList.GetOwner: TPersistent;
begin
Result := FHolder;
end;
procedure TODTStylesList.SetItem(Index: integer; Value: TODTCellParagraphStyle);
begin
inherited SetItem(Index, Value);
end;
{ TODSStylesList }
function TODSStylesList.Add: TODSStripCellParagraphStyle;
begin
Result := TODSStripCellParagraphStyle(inherited Add);
end;
constructor TODSStylesList.Create(Holder: TPersistent);
begin
inherited Create(TODSStripCellParagraphStyle);
FHolder := Holder;
end;
function TODSStylesList.GetItem(Index: Integer): TODSStripCellParagraphStyle;
begin
Result := inherited GetItem(Index) as TODSStripCellParagraphStyle;
end;
function TODSStylesList.GetOwner: TPersistent;
begin
Result := FHolder;
end;
procedure TODSStylesList.SetItem(Index: integer; Value: TODSStripCellParagraphStyle);
begin
inherited SetItem(Index, Value);
end;
{ TODSCellParagraphStyle }
procedure TODSCellParagraphStyle.Assign(Source: TPersistent);
begin
if Source is TODSCellParagraphStyle then
begin
VerticalAligment := (Source as TODSCellParagraphStyle).VerticalAligment;
Border := (Source as TODSCellParagraphStyle).Border;
inherited Assign(Source as TODSParagraphStyle);
Exit;
end;
inherited;
end;
constructor TODSCellParagraphStyle.Create(Collection: TCollection);
begin
inherited;
end;
destructor TODSCellParagraphStyle.Destroy;
begin
inherited;
FBorder.Free;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -