Flexcel Picture in Header

I want to set a Picture in the Left Header of a Excelfile and a LeftAligned Text in the Right Header.

I have found how to set the Text in the Header, but cant make it LeftAlined in the Right Header.
Then i set a Image in Cell(1,1) but i want the image to set in the Header because the Image has a too big top-Margin in the Printed Excelfile.
Here some Code i tried:

    fs := TFileStream.Create('.\Logo\LogoXLSLinks328x100.png', fmOpenRead or fmShareDenyNone);
    try
      img := TUIImage.FromStream(fs);
      try
        ImgProps := TImageProperties_Create();
        ImgProps.Anchor := TClientAnchor.Create(TFlxAnchorType.MoveAndDontResize,
          1, 0, 1, 0, Trunc(img.Height), Trunc(img.Width), fXLS);
        ImgProps.ShapeName := 'HeaderLogo';
        // Adress in right Header Test
        fXLS.PageHeader:='&RAdressName' + #10 + 'AdressStreet ' + '          ' + #10 + 'Tel: 123456789' + #10 + 'Mobil: 0151 -123456789' + #10 + 'info@emailadress.de';
      finally
        img.Free;
      end;

      fs.Position := 0;
      fXLS.AddImage(fs, ImgProps);
    finally
      fs.Free;
    end;

How can i set the image in the Header with fXLS.PageHeader:='&G....

1 Like

I have found something to make a Image and a Text in the XLS-Header,
but the Text is always rightaligned.

VAR
  // For XLS-Header
  HeadersAndFooters: THeaderAndFooter;
  ms: TFileStream;
  HeaderImgData: TArray<Byte>;
  HeadImgProps: IHeaderOrFooterImageProperties;
begin
    // Kopfzeilen in XLS einbauen
    HeadersAndFooters := THeaderAndFooter.Create();
    HeadersAndFooters.AlignMargins := True;
    HeadersAndFooters.ScaleWithDoc := True;
    HeadersAndFooters.DiffFirstPage := False;
    HeadersAndFooters.DiffEvenPages := False;
    HeadersAndFooters.DefaultHeader := '&L&G';
    HeadersAndFooters.DefaultFooter := '';
    HeadersAndFooters.FirstHeader := '';
    HeadersAndFooters.FirstFooter := '';
    HeadersAndFooters.EvenHeader := '';
    HeadersAndFooters.EvenFooter := '';
    fXLS.SetPageHeaderAndFooter(HeadersAndFooters);
    ms := TFileStream.Create('.\Logo\LogoXLSLinks328x100.png', fmOpenRead or fmShareDenyNone);
    try
      SetLength(HeaderImgData, ms.Size);
      ms.Read(HeaderImgData[0], Length(HeaderImgData));
      HeadImgProps := THeaderOrFooterImageProperties_Create();
      HeadImgProps.Filename := 'LogoXLSLinks328x100';
      HeadImgProps.Anchor := THeaderOrFooterAnchor.Create(328, 100);
      fXLS.SetHeaderOrFooterImage(THeaderAndFooterKind.Default, THeaderAndFooterPos.HeaderLeft, HeaderImgData, TXlsImgType.Jpeg, HeadImgProps);
      fXLS.PageHeader := '&L&G&RName' + #10 + 'Street' + '          ' + #10 + 'Tel:0123';
    finally
      ms.Free;
    end;
end;

I get this with the help of APImate

Now i am searching for to make the Text in the right Headerfield leftalign.

Hi,
I sadly don't think it is possible to left-align the right section of the heading with Excel. If you are able to do it in Excel, APIMate should tell you how to do it in FlexCel, but I don't think it is possible. Probably the best here would be to either manually align the text left by adding spaces (but you should use a monospaced font), or use the left section for everything, again with lots of spaces to make some part of the text appear at the right of the page (but you need to calculate the spaces, and this will break if the user prints in a bigger or smaller page).

Thank you for your answer.
I can convert the Text in a picture an use this or i try to find the printersettings for the top margin and set it to the lowest level.
Then i use Row1,Col1 and Row1,col3 and put the Picture and the Text in this fields.
That i tried before but the Top Margin was to big after printing the document.
Now i have to find out where i can minimize the top margin of the dokument.

APIMate should be able to help you with the margins. Try setting the file as you want in Excel, then look at the code APIMate generates.