⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qexport4odt.pas

📁 Advanced.Export.Component.v4.01.rar,delphi 第三方控件
💻 PAS
📖 第 1 页 / 共 3 页
字号:
      ODTFile.WriteSpecificNode(1021, '', [], []);
    end;
  begin
    if (TypeOfOptions = 1) then
      SubRoutine(ODTOptions.HeaderStyle, 'Header');
    if (TypeOfOptions = 2) then
      SubRoutine(ODTOptions.FooterStyle, 'Footer');
    if (TypeOfOptions = 3) then
      SubRoutine(ODTOptions.CaptionRowStyle, 'CaptionRow');
    if (TypeOfOptions = 4) then
      SubRoutine(ODTOptions.DataStyle, 'DataStyle');
    if (TypeOfOptions > 4) then
      SubRoutine(ODTOptions.StripStylesList[TypeOfOptions - 5],
        'StripStyle' + IntToStr(TypeOfOptions - 4));
  end;

  procedure AddLayersAndEnderBorderStyles;
  var
    Condition: Boolean;
    Num, CheckNum, I: Integer;
  begin
    //Check of data existence in formed table
    Condition := ((FRowCounter > 1)
      and (AllowCaptions)) or ((FRowCounter >= 1) and not(AllowCaptions));
    //Only caption row used - we should define border styles
    //only for caption row
    if (FRowCounter = 1) and (AllowCaptions) then
    begin
      WriteCellStyleNode(1, 'Layer');
      WriteCellStyleNode(1, 'LayerEnder');
    end;
    //At least one row in table exists - need to form data styles
    if (ODTOptions.StripStyle = sstNone) and Condition then
    begin
      if (AllowCaptions) then
        WriteCellStyleNode(1, 'Ender');      
      WriteCellStyleNode(2, 'Layer');
      WriteCellStyleNode(2, 'LayerEnder');
      WriteCellStyleNode(2, 'Ender');
    end;
    //At least one row in table exists and row style defined
    //need to make all ender/layer borders for strip styles
    if (ODTOptions.StripStyle = sstRow) and Condition then
    begin
      if (AllowCaptions) then
      begin
        Num := (FRowCounter - 1) mod ODTOptions.StripStylesList.Count;
        CheckNum := (FRowCounter - 1) div ODTOptions.StripStylesList.Count;
      end
      else
      begin
        Num := FRowCounter mod ODTOptions.StripStylesList.Count;
        CheckNum := FRowCounter div ODTOptions.StripStylesList.Count;
      end;
      if Num = 0 then
        Num := ODTOptions.StripStylesList.Count;
      //if Row Counter greater than number of strip styles
      //then form all ender strip styles
      //in other cases - form till num achived
      if CheckNum > 0 then
        for I := 0 to ODTOptions.StripStylesList.Count - 1 do
          WriteCellStyleNode(I + 3, 'Ender')
      else
        for I := 0 to Num - 2 do
          WriteCellStyleNode(I + 3, 'Ender');
      //The last strip style must have layer
      WriteCellStyleNode(Num + 2, 'Layer');
      WriteCellStyleNode(Num + 2, 'LayerEnder');
      if (AllowCaptions) then
        WriteCellStyleNode(1, 'Ender');
    end;
    if (ODTOptions.StripStyle = sstColumn) and Condition then
    begin
      Num := Columns.Count mod ODTOptions.StripStylesList.Count;
      if Num = 0 then
        Num := ODTOptions.StripStylesList.Count;
      if (Columns.Count div ODTOptions.StripStylesList.Count) > 0 then
        for I := 0 to ODTOptions.StripStylesList.Count - 1 do
          WriteCellStyleNode(I + 3, 'Layer')
      else
        for I := 0 to Num - 1 do
          WriteCellStyleNode(I + 3, 'Layer');
      //The last strip style must have layer
      WriteCellStyleNode(Num + 2, 'Ender');
      WriteCellStyleNode(Num + 2, 'LayerEnder');
      if (AllowCaptions) then
        WriteCellStyleNode(1, 'Ender');      
    end;
  end;
begin
  //+-------------------------------------+
  //|Default face-fonts processing section|
  //+-------------------------------------+
  ODTFile.OpenStream('facefont.xml');
  ODTFile.OpenWriter;
  for I := 1 to 4 do
  begin
    WriteFontStyleNode(I);
  end;
  for I := 0 to ODTOptions.StripStylesList.Count - 1 do
  begin
    WriteFontStyleNode(I + 5);
  end;
  ODTFile.WriteSpecificNode(1010, '', [], []);
  ODTFile.CloseWriter;
  ODTFile.CloseStream;
  ODTOptions.FontList.Clear;
  ODTFile.OpenStream('facefontstyles.xml');
  ODTFile.OpenWriter;
  for I := 1 to 4 do
    WriteFontStyleNode(I);
  for I := 0 to ODTOptions.StripStylesList.Count - 1 do
    WriteFontStyleNode(I + 5);
  ODTFile.WriteSpecificNode(1010, '', [], []);
  ODTFile.CloseWriter;
  ODTFile.CloseStream;
  //+-----------------------+
  //|Styles creation section|
  //+-----------------------+
  ODTFile.OpenStream('auto.xml');
  ODTFile.OpenWriter;
  ODTFile.WriteSpecificNode(11, '', [], []);
  for I := 1 to 2 do
    WriteCellStyleNode(I, '');
  for I := 0 to ODTOptions.StripStylesList.Count - 1 do
    WriteCellStyleNode(I + 3, '');
  //If Row counter > 0 and we're using border
  //then we have to add border and layer styles section
  if (ODTOptions.Border.BorderStyle = bsODFSolid) and (FRowCounter > 0) then
    AddLayersAndEnderBorderStyles;
  for I := 1 to 4 do
    WriteParagraphStyleNode(I);
  for I := 0 to ODTOptions.StripStylesList.Count - 1 do
    WriteParagraphStyleNode(I + 5);
  ODTFile.WriteSpecificNode(1011, '', [], []);
  ODTFile.WriteSpecificNode(12, '', [], []);
  ODTFile.WriteSpecificNode(14, '', [], []);
  ODTFile.CloseWriter;
  ODTFile.CloseStream;
  ODTFile.OpenStream('autoStyles.xml');
  ODTFile.OpenWriter;
  ODTFile.WriteSpecificNode(27, '', [], []);
  for I := 1 to 2 do
    WriteCellStyleNode(I, '');
  for I := 0 to ODTOptions.StripStylesList.Count - 1 do
    WriteCellStyleNode(I + 3, '');
  //If Row counter > 0 and we're using border
  //then we have to add border and layer styles section
  if (ODTOptions.Border.BorderStyle = bsODFSolid) and (FRowCounter > 0) then
    AddLayersAndEnderBorderStyles;
  for I := 1 to 4 do
    WriteParagraphStyleNode(I);
  for I := 0 to ODTOptions.StripStylesList.Count - 1 do
    WriteParagraphStyleNode(I + 5);
  ODTFile.WriteSpecificNode(1027, '', [], []);
  ODTFile.WriteSpecificNode(211, '', [], []);
  ODTFile.WriteSpecificNode(1028, '', [], []);
  ODTFile.CloseWriter;
  ODTFile.CloseStream;
end;

procedure TQExport4ODT.AfterExport;
begin                       
  if (FRowCounter = 0) then
    WriteBufferedRow(2)
  else
    WriteBufferedRow(3);
end;

procedure TQExport4ODT.BeginExport;
var
  i: Integer;
  temp: WideString;
begin
  inherited;
  ODTFile.Renew;
  FRowCounter := 0;
  SetLength(FBufferRow, Columns.Count);
  ClearBufferedRow;
  ODTFile.TypeConvert := 0;
  ODTFile.FileName := Self.FileName;
  ODTFile.MakeAll;

  ODTFile.OpenStream('table.xml');
  ODTFile.OpenWriter;
  ODTFile.CheckStatus;
  for i := 0 to Header.Count - 1 do
  begin
    temp := Header[I];
    ODTFile.WriteSpecificNode(18, ReplaceSymbols(Temp), ['text:style-name'], ['Header']);
  end;
  ODTFile.WriteSpecificNode(15, '', ['table:name'], [TableName]);
  for i := 0 to Columns.Count - 1 do
    ODTFile.WriteSpecificNode(19, '', ['table:style-name'], ['DefaultColumnStyle']);
end;

procedure TQExport4ODT.ClearBufferedRow;
var
  i: Integer;
begin
  for i := 0 to Length(FBufferRow) - 1 do
    FBufferRow[i] := '';
end;

function TQExport4ODT.ColorToString(Color: TColor): string;

  procedure SwapNums(Num1, Num2: Integer; var SwapStr: String);
  var
    a: char;
  begin
    a := SwapStr[Num1];
    SwapStr[Num1] := SwapStr[Num2];
    SwapStr[Num2] := a;
  end;

begin
  //Get Standard TColor representation
  FmtStr(Result, '%.6x', [Color]);
  //Swap 2 bytes to get defaul RGB representation
  SwapNums(1, 5, Result);
  SwapNums(2, 6, Result);
  Result := '#' + Result;
end;

constructor TQExport4ODT.Create(AOwner: TComponent);
begin
  inherited;
  ODTFile := TBaseODFFile.Create;
  FODTOptions := TQExportODTOptions.Create(Self);
  FTableName := {$IFDEF WIN32}QExportLoadStr(QED_ODT_StandardTableName){$ENDIF}
     {$IFDEF LINUX}QED_ODT_StandardTableName{$ENDIF};
end;

destructor TQExport4ODT.Destroy;
begin
  ODTFile.Free;
  FODTOptions.Free;
  inherited;
end;

procedure TQExport4ODT.EndExport;
var
  i: Integer;
  temp: WideString;
begin
  if (AllowCaptions) then
    Inc(FRowCounter);
  ODTFile.WriteSpecificNode(1015, '', ['table:name'], [TableName]);
  for i := 0 to Footer.Count - 1 do
  begin
    temp := Footer[I];
    ODTFile.WriteSpecificNode(18, ReplaceSymbols(temp), ['text:style-name'], ['Footer']);
  end;
  ODTFile.CloseWriter;
  ODTFile.CloseStream;
  ODTFile.EndFormingContent;
  AddStyles;
  ODTFile.MergeContent('content.xml', ['first.xml', 'facefont.xml', 'auto.xml',
    'table.xml', 'last.xml' ]);
  ODTFile.MergeContent('styles.xml', ['firstSt.xml', 'facefontstyles.xml',
    'autoStyles.xml']);
  ODTFile.DeleteList(['first.xml', 'facefont.xml', 'auto.xml',
    'table.xml', 'last.xml', 'firstSt.xml', 'facefontstyles.xml',
    'autoStyles.xml']);
  ODTFile.Compress;
  inherited;
end;

procedure TQExport4ODT.Execute;
begin
  if TableName = '' then
    raise Exception.Create('Table name is not defined');
  DoExport;
  ShowResult;
end;


function TQExport4ODT.PointsToCms(Value: Integer): string;
  var
    TempString: string;
    Idx: Integer;
  begin
    if Value = 0 then
    begin
      Result := '0cm';
      Exit;
    end;
    TempString := FloatToStr(Value * 0.0352 / 2);
    Idx := QEPos(',', TempString);
    TempString[Idx] := '.';
    Result := Copy(TempString, 1, 5);
    Result := Result + 'cm';
end;

procedure TQExport4ODT.SetOptions(const Value: TQExportODTOptions);
begin
  FODTOptions.Assign(Value);
end;

procedure TQExport4ODT.WriteBufferedRow(TypeOfRow: Integer);
var
  i, Num: Integer;
begin
  Num := 0;
  //Default Caption row style w/o layer borders
  if TypeOfRow = 0 then
  begin
    if not AllowCaptions then Exit;
    ODTFile.WriteSpecificNode(30, '', [], []);
    ODTFile.WriteSpecificNode(16, '', [], []);
    for i := 0 to Length(FBufferRow) - 1 do
    begin
      if (i < Columns.Count - 1) then
        ODTFile.WriteSpecificNode(17, '', ['table:style-name',
          'office:value-type'], ['CaptionCellRow', 'string'])
      else
      begin
        if ODTOptions.Border.BorderStyle = bsODFSolid then
          ODTFile.WriteSpecificNode(17, '', ['table:style-name',
            'office:value-type'], ['EnderCaptionCellRow', 'string'])
        else
          ODTFile.WriteSpecificNode(17, '', ['table:style-name',
            'office:value-type'], ['CaptionCellRow', 'string']);
      end;
      ODTFile.WriteSpecificNode(18, FBufferRow[i], ['text:style-name'],
        ['CaptionRow']);
      ODTFile.WriteSpecificNode(1017, '', [], []);
    end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -