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

📄 qexport4docx.pas

📁 Advanced.Export.Component.v4.01.rar,delphi 第三方控件
💻 PAS
📖 第 1 页 / 共 2 页
字号:

{ TDocxStripStyleList }

function TDocxStripStyleList.GetItem(Index: Integer): TDocxStripStyle;
begin
  Result := TDocxStripStyle(inherited Items[Index]);
end;

procedure TDocxStripStyleList.SetItem(Index: Integer;
  Value: TDocxStripStyle);
begin
  inherited Items[Index] := Value;
end;

function TDocxStripStyleList.Add: TDocxStripStyle;
begin
  Result := TDocxStripStyle(inherited Add)
end;

{ TDocxCellStyle }

function TDocxCellStyle.GetIsDefault: Boolean;
begin
  Result := (FFont.Name = 'Calibri')
    and (FFont.Size = 11)
    and (FFont.Style = [])
    and (FFont.Color = clBlack)
    and (FBackgroundColor = clWhite)
    and (FUseBackground = False)
    and (FAlignment = caLeft);
end;

procedure TDocxCellStyle.SetDefault(const Value: Boolean);
begin
  if Value then
  begin
    FFont.Name := 'Calibri';
    FFont.Size := 11;
    FFont.Style := [];
    FFont.Color := clBlack;
    FBackgroundColor := clWhite;
    FUseBackground := False;
    FAlignment := caLeft;
  end;
end;

procedure TDocxCellStyle.SetFont(const Value: TFont);
begin
  FFont.Assign(Value);
end;

constructor TDocxCellStyle.Create;
begin
  FFont := TFont.Create;
  Default;
end;

destructor TDocxCellStyle.Destroy;
begin
  FFont.Free;
  inherited;
end;

procedure TDocxCellStyle.Assign(Source: TPersistent);
begin
  if Source is TDocxCellStyle then
  begin
    Font := TDocxCellStyle(Source).Font;
    UseBackground := TDocxCellStyle(Source).UseBackground;
    BackgroundColor := TDocxCellStyle(Source).BackgroundColor;
    UseHighlight := TDocxCellStyle(Source).UseHighlight;
    HighlightColor := TDocxCellStyle(Source).HighlightColor;
    Alignment := TDocxCellStyle(Source).Alignment;
  end;
end;

procedure TDocxCellStyle.LoadFromIni(IniFile: TQIniFile;
  const Section: WideString);
begin
  with IniFile do
  begin
    Font.Name := ReadString(Section, S_DOCX_FontName, 'Calibri');
    Font.Size := ReadInteger(Section, S_DOCX_FontSize, 11);
    Font.Color := ReadInteger(Section, S_DOCX_FontColor, clBlack);
    if ReadBool(Section, S_DOCX_FontBold, False) then
      Font.Style := Font.Style + [fsBold]
    else
      Font.Style := Font.Style - [fsBold];
    if ReadBool(Section, S_DOCX_FontItalic, False) then
      Font.Style := Font.Style + [fsItalic]
    else
      Font.Style := Font.Style - [fsItalic];
    if ReadBool(Section, S_DOCX_FontUnderline, False) then
      Font.Style := Font.Style + [fsUnderline]
    else
      Font.Style := Font.Style - [fsUnderline];
    if ReadBool(Section, S_DOCX_StrikeOut, False) then
      Font.Style := Font.Style + [fsStrikeOut]
    else
      Font.Style := Font.Style - [fsStrikeOut];
    Alignment := TMSCellAlignment(ReadInteger(Section, S_DOCX_HorAlignment, 0));
    UseBackground := ReadBool(Section, S_DOCX_UseBackground, False);
    BackgroundColor := ReadInteger(Section, S_DOCX_BackgroundColor, clBlack);
  end;
end;

procedure TDocxCellStyle.SaveToIni(IniFile: TQIniFile;
  const Section: WideString);
begin
  with IniFile do
  begin
    WriteString(Section, S_DOCX_FontName, Font.Name);
    WriteInteger(Section, S_DOCX_FontSize, Font.Size);
    WriteInteger(Section, S_DOCX_FontColor, Font.Color);
    if fsBold in Font.Style then
      WriteBool(Section, S_DOCX_FontBold, true)
    else
      WriteBool(Section, S_DOCX_FontBold, false);
    if fsItalic in Font.Style then
      WriteBool(Section, S_DOCX_FontItalic, true)
    else
      WriteBool(Section, S_DOCX_FontItalic, false);
    if fsUnderline in Font.Style then
      WriteBool(Section, S_DOCX_FontUnderline, true)
    else
      WriteBool(Section, S_DOCX_FontUnderline, false);
    if fsStrikeOut in Font.Style then
      WriteBool(Section, S_DOCX_StrikeOut, true)
    else
      WriteBool(Section, S_DOCX_StrikeOut, false);
    WriteBool(Section, S_DOCX_UseBackground, UseBackground);
    WriteInteger(Section, S_DOCX_BackgroundColor, BackgroundColor);
    WriteInteger(Section, S_DOCX_HorAlignment, Integer(Alignment));
    WriteBool(Section, S_DOCX_UseHighlight, UseBackground);
    WriteInteger(Section, S_DOCX_HighlightColor, Integer(HighlightColor));
  end;
end;

procedure TDocxCellStyle.Default;
begin
  FFont.Name := 'Calibri';
  FFont.Size := 11;
  FFont.Style := [];
  FFont.Color := clBlack;
  FUseBackground := False;
  FBackgroundColor := clWhite;
  FUseHighlight := False;
  FHighlightColor := hcNone;
  FAlignment := caLeft;
end;

{ TQExport4DocxOptions }

procedure TQExport4DocxOptions.SetHeaderStyle(const Value: TDocxCellStyle);
begin
  FHeaderStyle.Assign(Value);
end;

procedure TQExport4DocxOptions.SetCaptionStyle(
  const Value: TDocxCellStyle);
begin
  FCaptionRowStyle.Assign(Value);
end;

procedure TQExport4DocxOptions.SetDataStyle(const Value: TDocxCellStyle);
begin
  FDataStyle.Assign(Value);
end;

procedure TQExport4DocxOptions.SetStripStyles(
  const Value: TDocxStripStyleList);
begin
  FStripStylesList.Assign(Value);
end;

procedure TQExport4DocxOptions.SetFooterStyle(const Value: TDocxCellStyle);
begin
  FFooterStyle.Assign(Value);
end;

procedure TQExport4DocxOptions.SetBorder(const Value: TDocxBorder);
begin
  FBorder.Assign(Value);
end;

constructor TQExport4DocxOptions.Create(Holder: TPersistent);
begin
  inherited Create;
  FHeaderStyle := TDocxCellStyle.Create;
  FCaptionRowStyle := TDocxCellStyle.Create;
  FDataStyle := TDocxCellStyle.Create;
  FStripStyle := ssNone;
  FStripStylesList := TDocxStripStyleList.Create(TDocxStripStyle);
  FFooterStyle := TDocxCellStyle.Create;
  FUseBorder := False;
  FBorder := TDocxBorder.Create;
end;

destructor TQExport4DocxOptions.Destroy;
begin
  FHeaderStyle.Free;
  FCaptionRowStyle.Free;
  FDataStyle.Free;
  FStripStylesList.Free;
  FFooterStyle.Free;
  FBorder.Free;
  inherited;
end;

procedure TQExport4DocxOptions.Assign(Source: TPersistent);
begin
  if Source is TQExport4DocxOptions then
  begin
    HeaderStyle := TQExport4DocxOptions(Source).HeaderStyle;
    CaptionRowStyle := TQExport4DocxOptions(Source).CaptionRowStyle;
    DataStyle := TQExport4DocxOptions(Source).DataStyle;
    StripStyleType := TQExport4DocxOptions(Source).StripStyleType;
    StripStylesList := TQExport4DocxOptions(Source).StripStylesList;
    FooterStyle := TQExport4DocxOptions(Source).FooterStyle;
    UseBorder := TQExport4DocxOptions(Source).UseBorder;
    if UseBorder then
    begin
      Border.Style := TQExport4DocxOptions(Source).Border.Style;
      Border.Color := TQExport4DocxOptions(Source).Border.Color;
    end;
  end;
end;

{ TDocxFileMaker }

procedure TDocxFileMaker.SetIsColumnsSectionReady(const Value: Boolean);
var
  i: Integer;
begin
  if Value then
  begin
    FExportWriter.BeginNode('w:tblGrid', '', [], []);
    for i := 0 to FColumnsCount - 1 do
      FExportWriter.CreateFullNode('w:gridCol', '', ['w:w'], ['2392']);
    FExportWriter.EndNode('w:tblGrid');
    FIsColumnsSectionReady := Value;
  end;
end;

procedure TDocxFileMaker.AddCell(Value: WideString; CellStyle: TDocxCellStyle;
  Border: TDocxBorder);
begin
  with FExportWriter do
  begin
    BeginNode('w:tc', '', [], []);

    BeginNode('w:tcPr', '', [], []);
    CreateFullNode('w:tcW', '', ['w:w', 'w:type'], ['2392', 'dxa']);
    if Assigned(Border) then
    begin
      BeginNode('w:tcBorders', '', [], []);
      CreateFullNode('w:top', '', ['w:val', 'w:sz', 'w:space', 'w:color'],
        [MSBorderStyleToStr(Border.Style), '4', '0', ColorToHex(Border.Color)]);
      CreateFullNode('w:left', '', ['w:val', 'w:sz', 'w:space', 'w:color'],
        [MSBorderStyleToStr(Border.Style), '4', '0', ColorToHex(Border.Color)]);
      CreateFullNode('w:bottom', '', ['w:val', 'w:sz', 'w:space', 'w:color'],
        [MSBorderStyleToStr(Border.Style), '4', '0', ColorToHex(Border.Color)]);
      CreateFullNode('w:right', '', ['w:val', 'w:sz', 'w:space', 'w:color'],
        [MSBorderStyleToStr(Border.Style), '4', '0', ColorToHex(Border.Color)]);
      EndNode('w:tcBorders');
    end;
    
    if CellStyle.UseBackground and (CellStyle.BackgroundColor <> clWhite)  then
      CreateFullNode('w:shd', '', ['w:val', 'w:color', 'w:fill'],
        ['clear', 'auto', ColorToHex(CellStyle.BackgroundColor)]);

    EndNode('w:tcPr');

    BeginNode('w:p', '', [], []);
    
    BeginNode('w:pPr', '', [], []);
    case CellStyle.Alignment of
      caCenter: CreateFullNode('w:jc', '', ['w:val'], ['center']);
      caRight: CreateFullNode('w:jc', '', ['w:val'], ['right']);
      caJustify: CreateFullNode('w:jc', '', ['w:val'], ['both']);
    end;

    BeginNode('w:rPr', '', [], []);
//    if CellStyle.Font.Color <> clBlack then
//      CreateFullNode('w:color', '', ['w:val'], [ColorToHex(CellStyle.Font.Color)]);
//  

⌨️ 快捷键说明

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