fpspreadsheet: Add richtext demo.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7996 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
1cc0c3b66c
commit
d4a2ee4773
@ -93,9 +93,9 @@ begin
|
|||||||
book := TsWorkbook.Create;
|
book := TsWorkbook.Create;
|
||||||
try
|
try
|
||||||
// Select one of these
|
// Select one of these
|
||||||
// book.ReadFromFile('test.ods');
|
// book.ReadFromFile(dir + 'test.ods');
|
||||||
// book.ReadFromFile('test.xlsx');
|
// book.ReadFromFile(dir + 'test.xlsx');
|
||||||
book.ReadFromFile('test.xml');
|
book.ReadFromFile(dir + 'test.xml');
|
||||||
WriteLn('Created by : ', book.MetaData.CreatedBy);
|
WriteLn('Created by : ', book.MetaData.CreatedBy);
|
||||||
WriteLn('Date created : ', DateTimeToStr(book.MetaData.DateCreated));
|
WriteLn('Date created : ', DateTimeToStr(book.MetaData.DateCreated));
|
||||||
WriteLn('Modified by : ', book.MetaData.LastModifiedBy);
|
WriteLn('Modified by : ', book.MetaData.LastModifiedBy);
|
||||||
|
@ -57,6 +57,11 @@
|
|||||||
<Mode Name="Default"/>
|
<Mode Name="Default"/>
|
||||||
</BuildModes>
|
</BuildModes>
|
||||||
</Target>
|
</Target>
|
||||||
|
<Target FileName="richtext\demo_richtext_utf8.lpi">
|
||||||
|
<BuildModes>
|
||||||
|
<Mode Name="Default"/>
|
||||||
|
</BuildModes>
|
||||||
|
</Target>
|
||||||
<Target FileName="rpn_formulas\demo_write_formula.lpi">
|
<Target FileName="rpn_formulas\demo_write_formula.lpi">
|
||||||
<BuildModes>
|
<BuildModes>
|
||||||
<Mode Name="Debug" Compile="True"/>
|
<Mode Name="Debug" Compile="True"/>
|
||||||
|
@ -26,6 +26,8 @@ This folder contains various demo applications:
|
|||||||
in the first cell is calculated recursive calculation of the other cells
|
in the first cell is calculated recursive calculation of the other cells
|
||||||
is requested.
|
is requested.
|
||||||
|
|
||||||
|
- richtext/demo_richtext_utf8: shows working with rich text formatting in cells
|
||||||
|
|
||||||
- rpn_formulas/demo_write_formula: shows some rpn formulas
|
- rpn_formulas/demo_write_formula: shows some rpn formulas
|
||||||
|
|
||||||
- searching/demo_search: demonstrates how specific cell content can be
|
- searching/demo_search: demonstrates how specific cell content can be
|
||||||
|
@ -0,0 +1,63 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<CONFIG>
|
||||||
|
<ProjectOptions>
|
||||||
|
<Version Value="12"/>
|
||||||
|
<PathDelim Value="\"/>
|
||||||
|
<General>
|
||||||
|
<Flags>
|
||||||
|
<MainUnitHasCreateFormStatements Value="False"/>
|
||||||
|
<MainUnitHasTitleStatement Value="False"/>
|
||||||
|
<MainUnitHasScaledStatement Value="False"/>
|
||||||
|
<CompatibilityMode Value="True"/>
|
||||||
|
</Flags>
|
||||||
|
<SessionStorage Value="InProjectDir"/>
|
||||||
|
<Title Value="demo_richtext_utf8"/>
|
||||||
|
<UseAppBundle Value="False"/>
|
||||||
|
<ResourceType Value="res"/>
|
||||||
|
</General>
|
||||||
|
<BuildModes Count="1">
|
||||||
|
<Item1 Name="Default" Default="True"/>
|
||||||
|
</BuildModes>
|
||||||
|
<PublishOptions>
|
||||||
|
<Version Value="2"/>
|
||||||
|
</PublishOptions>
|
||||||
|
<RunParams>
|
||||||
|
<FormatVersion Value="2"/>
|
||||||
|
</RunParams>
|
||||||
|
<RequiredPackages Count="1">
|
||||||
|
<Item1>
|
||||||
|
<PackageName Value="laz_fpspreadsheet"/>
|
||||||
|
</Item1>
|
||||||
|
</RequiredPackages>
|
||||||
|
<Units Count="1">
|
||||||
|
<Unit0>
|
||||||
|
<Filename Value="demo_richtext_utf8.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit0>
|
||||||
|
</Units>
|
||||||
|
</ProjectOptions>
|
||||||
|
<CompilerOptions>
|
||||||
|
<Version Value="11"/>
|
||||||
|
<PathDelim Value="\"/>
|
||||||
|
<Target>
|
||||||
|
<Filename Value="demo_richtext_utf8"/>
|
||||||
|
</Target>
|
||||||
|
<SearchPaths>
|
||||||
|
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||||
|
<UnitOutputDirectory Value="..\..\lib\$(TargetCPU)-$(TargetOS)"/>
|
||||||
|
</SearchPaths>
|
||||||
|
</CompilerOptions>
|
||||||
|
<Debugging>
|
||||||
|
<Exceptions Count="3">
|
||||||
|
<Item1>
|
||||||
|
<Name Value="EAbort"/>
|
||||||
|
</Item1>
|
||||||
|
<Item2>
|
||||||
|
<Name Value="ECodetoolError"/>
|
||||||
|
</Item2>
|
||||||
|
<Item3>
|
||||||
|
<Name Value="EFOpenError"/>
|
||||||
|
</Item3>
|
||||||
|
</Exceptions>
|
||||||
|
</Debugging>
|
||||||
|
</CONFIG>
|
@ -0,0 +1,63 @@
|
|||||||
|
program demo_richtext_utf8;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
uses
|
||||||
|
SysUtils, fpstypes, fpspreadsheet, xlsxooxml, typinfo;
|
||||||
|
|
||||||
|
var
|
||||||
|
book: TsWorkbook;
|
||||||
|
sheet: TsWorksheet;
|
||||||
|
cell: PCell;
|
||||||
|
i: Integer;
|
||||||
|
rtp: TsRichTextParam;
|
||||||
|
fmt: TsCellFormat;
|
||||||
|
dir: String;
|
||||||
|
begin
|
||||||
|
dir := ExtractFilePath(ParamStr(0));
|
||||||
|
|
||||||
|
book := TsWorkbook.Create;
|
||||||
|
try
|
||||||
|
// Prepare a worksheet containing rich-text in cell A1
|
||||||
|
sheet := book.AddWorksheet('Sheet');
|
||||||
|
sheet.WriteTextAsHtml(0, 0, 'äöü <b>ÄÖÜ</b> 123');
|
||||||
|
|
||||||
|
// -----------------------------------------
|
||||||
|
// Analyze the fonts used in cell A1
|
||||||
|
//------------------------------------------
|
||||||
|
|
||||||
|
cell := sheet.FindCell(0, 0);
|
||||||
|
|
||||||
|
// Write a "ruler" for counting character positions
|
||||||
|
WriteLn('12345678901234567890');
|
||||||
|
// Write the unformatted cell text
|
||||||
|
WriteLn(sheet.ReadAsText(cell));
|
||||||
|
WriteLn;
|
||||||
|
|
||||||
|
// characters before the first rich-text parameter have the cell font
|
||||||
|
fmt := book.GetCellFormat(cell^.FormatIndex); // get cell format record which contains the font index
|
||||||
|
WriteLn(Format('Initial cell font: #%d (%s)', [fmt.FontIndex, book.GetFontAsString(fmt.FontIndex)]));
|
||||||
|
|
||||||
|
// now write the rich-text parameters
|
||||||
|
for rtp in cell^.RichTextParams do begin
|
||||||
|
WriteLn(Format('Font #%d (%s) starting at character position %d', [
|
||||||
|
rtp.FontIndex,
|
||||||
|
book.GetFontAsString(rtp.FontIndex),
|
||||||
|
rtp.FirstIndex
|
||||||
|
]));
|
||||||
|
end;
|
||||||
|
|
||||||
|
book.WriteToFile(dir+'test.xlsx', true);
|
||||||
|
finally
|
||||||
|
book.Free;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{$IFDEF MSWindows}
|
||||||
|
if ParamCount = 0 then
|
||||||
|
begin
|
||||||
|
WriteLn('Press ENTER to close...');
|
||||||
|
ReadLn;
|
||||||
|
end;
|
||||||
|
{$ENDIF}
|
||||||
|
end.
|
||||||
|
|
@ -9,6 +9,7 @@ images\demo_write_images -quit
|
|||||||
metadata\demo_metadata -quit
|
metadata\demo_metadata -quit
|
||||||
protection\demo_protection -quit
|
protection\demo_protection -quit
|
||||||
recursive_calculation\demo_recursive_calc -quit
|
recursive_calculation\demo_recursive_calc -quit
|
||||||
|
richtext\demo_richtext_utf8 -quit
|
||||||
rpn_formulas\demo_write_formula -quit
|
rpn_formulas\demo_write_formula -quit
|
||||||
searching\demo_search -quit
|
searching\demo_search -quit
|
||||||
sorting\demo_sorting -quit
|
sorting\demo_sorting -quit
|
||||||
|
Loading…
Reference in New Issue
Block a user