fpspreadsheet: Finalize image and headerfooter_image demos. Update readme in other demos folder.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4547 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-03-13 23:01:12 +00:00
parent 44b8adf293
commit 2a026867ca
4 changed files with 62 additions and 46 deletions

View File

@ -19,35 +19,42 @@ const
image3 = '../../images/components/TSCELLEDIT.png'; image3 = '../../images/components/TSCELLEDIT.png';
begin begin
Writeln('Starting program "demo_write_headerfooter_images"...');
// Create the spreadsheet // Create the spreadsheet
MyWorkbook := TsWorkbook.Create; MyWorkbook := TsWorkbook.Create;
MyWorkbook.Options := [boFileStream]; try
MyWorksheet := MyWorkbook.AddWorksheet('Sheet 1');
MyWorksheet.WriteText(0, 0, 'The header of this sheet contains an image');
MyWorksheet.PageLayout.HeaderMargin := 10;
MyWorksheet.Pagelayout.TopMargin := 30; // the header is 20 mm high
MyWorksheet.PageLayout.Headers[HEADER_FOOTER_INDEX_ALL] := '&CHeader with image!';
MyWorksheet.PageLayout.AddHeaderImage(HEADER_FOOTER_INDEX_ALL, hfsLeft, image1);
MyWorksheet := MyWorkbook.AddWorksheet('Sheet 1'); MyWorksheet := MyWorkbook.AddWorksheet('Sheet 2');
MyWorksheet.WriteText(0, 0, 'The header of this sheet contains an image'); MyWorksheet.WriteText(0, 0, 'The footer of this sheet contains an image');
MyWorksheet.Pagelayout.TopMargin := 30; MyWorksheet.PageLayout.Footers[HEADER_FOOTER_INDEX_ALL] := '&CFooter with image!';
MyWorksheet.PageLayout.HeaderMargin := 10; //25; MyWorksheet.PageLayout.AddFooterImage(HEADER_FOOTER_INDEX_ALL, hfsRight, image2);
MyWorksheet.PageLayout.Headers[HEADER_FOOTER_INDEX_ALL] := '&CHeader with image!';
// MyWorksheet.PageLayout.AddHeaderImage(HEADER_FOOTER_INDEX_ALL, hfsLeft, image1);
MyWorksheet := MyWorkbook.AddWorksheet('Sheet 2'); // Save the spreadsheet to files
MyWorksheet.WriteText(0, 0, 'The footer of this sheet contains an image'); MyDir := ExtractFilePath(ParamStr(0));
MyWorksheet.PageLayout.Footers[HEADER_FOOTER_INDEX_ALL] := '&CFooter with image!'; MyWorkbook.WriteToFile(MyDir + 'hfimg.xlsx', sfOOXML, true);
// MyWorksheet.PageLayout.AddFooterImage(HEADER_FOOTER_INDEX_ALL, hfsRight, image2); MyWorkbook.WriteToFile(MyDir + 'hfimg.ods', sfOpenDocument, true);
// Save the spreadsheet to a file
MyDir := ExtractFilePath(ParamStr(0));
MyWorkbook.WriteToFile(MyDir + 'hfimg.xlsx', sfOOXML, true);
MyWorkbook.WriteToFile(MyDir + 'hfimg.ods', sfOpenDocument, true);
// MyWorkbook.WriteToFile(MyDir + 'hfimg.xls', sfExcel8, true); // MyWorkbook.WriteToFile(MyDir + 'hfimg.xls', sfExcel8, true);
// MyWorkbook.WriteToFile(MyDir + 'hfimg5.xls', sfExcel5, true); // MyWorkbook.WriteToFile(MyDir + 'hfimg5.xls', sfExcel5, true);
// MyWorkbook.WriteToFile(MyDir + 'hfimg2.xls', sfExcel2, true); // MyWorkbook.WriteToFile(MyDir + 'hfimg2.xls', sfExcel2, true);
if MyWorkbook.ErrorMsg <> '' then if MyWorkbook.ErrorMsg <> '' then
begin WriteLn(MyWorkbook.ErrorMsg);
WriteLn(MyWorkbook.ErrorMsg);
end;
MyWorkbook.Free; WriteLn('Finished.');
WriteLn('Please open the files "hfimg.*" in your spreadsheet program.');
{$ifdef WINDOWS}
WriteLn('Press ENTER to close this program...');
ReadLn;
{$endif}
finally
MyWorkbook.Free;
end;
end. end.

View File

@ -19,37 +19,42 @@ const
image3 = '../../images/components/TSCELLEDIT.png'; image3 = '../../images/components/TSCELLEDIT.png';
begin begin
Writeln('Starting program "demo_write_images"...');
// Create the spreadsheet // Create the spreadsheet
MyWorkbook := TsWorkbook.Create; MyWorkbook := TsWorkbook.Create;
MyWorkbook.Options := [boFileStream]; try
MyWorksheet := MyWorkbook.AddWorksheet('Sheet 1');
MyWorksheet.DefaultRowHeight := 1.2;
MyWorksheet.WriteText(0, 0, 'There are images in cells A3 and B3'); //
// These images are offset by 1mm in both directions from the top/left cell edge
MyWorksheet.WriteImage(2, 0, image1, 1.0, 1.0, 2.0, 2.0); // This image is magnified by factor 2
MyWorksheet.WriteImage(2, 1, image2, 1.0, 1.0);
MyWorksheet := MyWorkbook.AddWorksheet('Sheet 1'); MyWorksheet := MyWorkbook.AddWorksheet('Sheet 2');
MyWorksheet.DefaultRowHeight := 1.2; MyWorksheet.WriteText(0, 0, 'There is an image in cell B3');
MyWorksheet.WriteText(0, 0, 'There are images in cells A3 and B3'); // MyWorksheet.WriteImage(2, 1, image3);
MyWorksheet.WriteImage(2, 0, image1, 1.0, 1.0, 2.0, 2.0);
MyWorksheet.WriteImage(2, 1, image2, 1.0, 1.0); // Save the spreadsheet to files
{ MyDir := ExtractFilePath(ParamStr(0));
MyWorksheet := MyWorkbook.AddWorksheet('Sheet 2'); MyWorkbook.WriteToFile(MyDir + 'img.xlsx', sfOOXML, true);
MyWorksheet.WriteText(0, 0, 'There is an image in cell B3'); MyWorkbook.WriteToFile(MyDir + 'img.ods', sfOpenDocument, true);
MyWorksheet.WriteImage(2, 1, image3);
// MyWorksheet.WriteImage(0, 2, 'D:\Prog_Lazarus\svn\lazarus-ccr\components\fpspreadsheet\examples\read_write\ooxmldemo\laz_open.png');
// MyWorksheet.WriteHyperlink(0, 0, 'http://www.chip.de');
// MyWorksheet.PageLayout.AddHeaderImage(1, hfsLeft, 'D:\Prog_Lazarus\svn\lazarus-ccr\components\fpspreadsheet\examples\read_write\ooxmldemo\laz_open.png');
// MyWorksheet.PageLayout.Headers[1] := '&LThis is a header&R&G';
}
// Save the spreadsheet to a file
MyDir := ExtractFilePath(ParamStr(0));
MyWorkbook.WriteToFile(MyDir + 'img.xlsx', sfOOXML, true);
MyWorkbook.WriteToFile(MyDir + 'img.ods', sfOpenDocument, true);
// MyWorkbook.WriteToFile(MyDir + 'img.xls', sfExcel8, true); // MyWorkbook.WriteToFile(MyDir + 'img.xls', sfExcel8, true);
// MyWorkbook.WriteToFile(MyDir + 'img5.xls', sfExcel5, true); // MyWorkbook.WriteToFile(MyDir + 'img5.xls', sfExcel5, true);
// MyWorkbook.WriteToFile(MyDir + 'img2.xls', sfExcel2, true); // MyWorkbook.WriteToFile(MyDir + 'img2.xls', sfExcel2, true);
if MyWorkbook.ErrorMsg <> '' then if MyWorkbook.ErrorMsg <> '' then
begin WriteLn(MyWorkbook.ErrorMsg);
WriteLn(MyWorkbook.ErrorMsg);
end;
MyWorkbook.Free; WriteLn('Finished.');
WriteLn('Please open the files "img.*" in your spreadsheet program.');
{$ifdef WINDOWS}
WriteLn('Press ENTER to close this program...');
ReadLn;
{$ENDIF}
finally
MyWorkbook.Free;
end;
end. end.

View File

@ -21,3 +21,7 @@ This folder contains various demo applications:
- demo_write_formatting: shows some simple cell formatting - demo_write_formatting: shows some simple cell formatting
- demo_write_formula: shows some rpn formulas - demo_write_formula: shows some rpn formulas
- demo_write_images: adds images to worksheets
- demo_write_headerfooter_images: adds images to worksheet headers and footers

View File

@ -5919,7 +5919,7 @@ function TsSpreadOpenDocWriter.WritePageLayoutAsXMLString(AStyleName: String;
AHeaderImageStr := IfThen((hdrImg = '') or (hdrImgPos = ''), '', Format( AHeaderImageStr := IfThen((hdrImg = '') or (hdrImgPos = ''), '', Format(
'<style:background-image xlink:href="Pictures/%s" '+ '<style:background-image xlink:href="Pictures/%s" '+
'xlink:type="simple" xlink:actuate="onLoad" '+ 'xlink:type="simple" xlink:actuate="onLoad" '+
'style:position="top %s" style:repeat="no-repeat" />', 'style:position="center %s" style:repeat="no-repeat" />',
[hdrImg, hdrImgPos] )); [hdrImg, hdrImgPos] ));
AFooterImageStr := IfThen((ftrImg = '') or (ftrImgPos = ''), '', Format( AFooterImageStr := IfThen((ftrImg = '') or (ftrImgPos = ''), '', Format(