fpspreadsheet: clean up examples: progress messages; remove win32 gui for console applications etc

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3362 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
bigchimp
2014-07-23 10:47:38 +00:00
parent 243d3b0c7d
commit 40e2a85bd1
7 changed files with 48 additions and 46 deletions

View File

@ -38,11 +38,6 @@
<StripSymbols Value="True"/> <StripSymbols Value="True"/>
</Debugging> </Debugging>
<LinkSmart Value="True"/> <LinkSmart Value="True"/>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking> </Linking>
</CompilerOptions> </CompilerOptions>
</Item2> </Item2>
@ -65,6 +60,7 @@
<Unit0> <Unit0>
<Filename Value="test_formula_func.pas"/> <Filename Value="test_formula_func.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="test_formula_func"/>
</Unit0> </Unit0>
<Unit1> <Unit1>
<Filename Value="financemath.pas"/> <Filename Value="financemath.pas"/>

View File

@ -1,8 +1,8 @@
{ This demo show how user-provided functions can be used for calculation of { This demo shows how user-provided functions can be used for calculation of
rpn formulas that are built-in to fpspreadsheet, but don't have an own RPN formulas that are built-in to fpspreadsheet, but don't have their own
calculation procedure. calculation procedure.
The example will show implementation of the some financial formulas: The example will show implementation of some financial formulas:
- FV() (future value) - FV() (future value)
- PV() (present value) - PV() (present value)
- PMT() (payment) - PMT() (payment)
@ -19,12 +19,13 @@ program test_formula_func;
{$mode delphi}{$H+} {$mode delphi}{$H+}
uses uses
{$IFDEF UNIX}{$IFDEF UseCThreads} {$IFDEF UNIX}
cthreads, {$IFDEF UseCThreads}
{$ENDIF}{$ENDIF} cthreads,
Classes, SysUtils, laz_fpspreadsheet {$ENDIF}
{ you can add units after this }, {$ENDIF}
math, fpspreadsheet, xlsbiff8, fpsfunc, financemath; Classes, SysUtils,
math, laz_fpspreadsheet, fpspreadsheet, xlsbiff8, fpsfunc, financemath;
{------------------------------------------------------------------------------} {------------------------------------------------------------------------------}
@ -65,6 +66,7 @@ begin
end; end;
function fpsPV(Args: TsArgumentStack; NumArgs: Integer): TsArgument; function fpsPV(Args: TsArgumentStack; NumArgs: Integer): TsArgument;
// Present value
var var
data: TsArgNumberArray; data: TsArgNumberArray;
begin begin
@ -121,7 +123,6 @@ var
workbook: TsWorkbook; workbook: TsWorkbook;
worksheet: TsWorksheet; worksheet: TsWorksheet;
fval, pval, pmtval, nperval, rateval: Double; fval, pval, pmtval, nperval, rateval: Double;
begin begin
{ We have to register our financial functions in fpspreadsheet. Otherwise an { We have to register our financial functions in fpspreadsheet. Otherwise an
error code would be displayed in the reading part of this demo for these error code would be displayed in the reading part of this demo for these
@ -326,7 +327,8 @@ begin
WriteLn('Contents of file "', AFileName, '"'); WriteLn('Contents of file "', AFileName, '"');
WriteLn(''); WriteLn('');
for r := 0 to worksheet.GetLastRowIndex do begin for r := 0 to worksheet.GetLastRowIndex do
begin
s1 := UTF8ToAnsi(worksheet.ReadAsUTF8Text(r, 0)); s1 := UTF8ToAnsi(worksheet.ReadAsUTF8Text(r, 0));
s2 := UTF8ToAnsi(worksheet.ReadAsUTF8Text(r, 1)); s2 := UTF8ToAnsi(worksheet.ReadAsUTF8Text(r, 1));
if s1 = '' then if s1 = '' then
@ -346,10 +348,11 @@ begin
end; end;
end; end;
const
TestFile='test_fv.xls';
begin begin
WriteFile('test_fv.xls'); WriteFile(TestFile);
ReadFile('test_fv.xls'); ReadFile(TestFile);
end. end.

View File

@ -38,11 +38,6 @@
<StripSymbols Value="True"/> <StripSymbols Value="True"/>
</Debugging> </Debugging>
<LinkSmart Value="True"/> <LinkSmart Value="True"/>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking> </Linking>
</CompilerOptions> </CompilerOptions>
</Item2> </Item2>
@ -64,6 +59,7 @@
<Unit0> <Unit0>
<Filename Value="test_recursive_calc.pas"/> <Filename Value="test_recursive_calc.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="test_recursive_calc"/>
</Unit0> </Unit0>
</Units> </Units>
</ProjectOptions> </ProjectOptions>
@ -78,13 +74,6 @@
<OptimizationLevel Value="0"/> <OptimizationLevel Value="0"/>
</Optimizations> </Optimizations>
</CodeGeneration> </CodeGeneration>
<Linking>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
</CompilerOptions> </CompilerOptions>
<Debugging> <Debugging>
<Exceptions Count="3"> <Exceptions Count="3">

View File

@ -9,18 +9,21 @@ program test_recursive_calc;
{$mode objfpc}{$H+} {$mode objfpc}{$H+}
uses uses
{$IFDEF UNIX}{$IFDEF UseCThreads} {$IFDEF UNIX}
{$IFDEF UseCThreads}
cthreads, cthreads,
{$ENDIF}{$ENDIF} {$ENDIF}
Classes, laz_fpspreadsheet {$ENDIF}
{ you can add units after this }, Classes,
math, fpspreadsheet, fpsfunc; math, laz_fpspreadsheet, fpspreadsheet, fpsfunc;
var var
workbook: TsWorkbook; workbook: TsWorkbook;
worksheet: TsWorksheet; worksheet: TsWorksheet;
const
OutputFile='test_calc.xls';
begin begin
writeln('Starting program.');
workbook := TsWorkbook.Create; workbook := TsWorkbook.Create;
try try
worksheet := workbook.AddWorksheet('Calc_test'); worksheet := workbook.AddWorksheet('Calc_test');
@ -48,7 +51,8 @@ begin
// B3 // B3
worksheet.WriteNumber(2, 1, 1); worksheet.WriteNumber(2, 1, 1);
workbook.WriteToFile('test_calc.xls', sfExcel8, true); workbook.WriteToFile(OutputFile, sfExcel8, true);
writeln('Finished. Please open "'+OutputFile+'" in your spreadsheet program.');
finally finally
workbook.Free; workbook.Free;
end; end;

View File

@ -3,12 +3,14 @@ program test_virtualmode;
{$mode objfpc}{$H+} {$mode objfpc}{$H+}
uses uses
{$IFDEF UNIX}{$IFDEF UseCThreads} {$IFDEF UNIX}
{$IFDEF UseCThreads}
cthreads, cthreads,
{$ENDIF}{$ENDIF} {$ENDIF}
Classes, laz_fpspreadsheet, {$ENDIF}
{ you can add units after this } lazutf8, Classes, SysUtils,
SysUtils, variants, fpspreadsheet, xlsbiff2, xlsbiff5, xlsbiff8, xlsxooxml; lazutf8,
variants, laz_fpspreadsheet, fpspreadsheet, xlsbiff2, xlsbiff5, xlsbiff8, xlsxooxml;
type type
TDataProvider = class TDataProvider = class

View File

@ -159,7 +159,10 @@ begin
MyCell^.UsedFormattingFields := [uffBorder, uffBackgroundColor]; MyCell^.UsedFormattingFields := [uffBorder, uffBackgroundColor];
end; end;
const
TestFile='test3.odt';
begin begin
writeln('Starting program.');
MyDir := ExtractFilePath(ParamStr(0)); MyDir := ExtractFilePath(ParamStr(0));
// Create the spreadsheet // Create the spreadsheet
@ -171,7 +174,8 @@ begin
// Save the spreadsheet to a file // Save the spreadsheet to a file
// MyWorkbook.WriteToFile(MyDir + 'test3.xls', sfExcel8, False); // MyWorkbook.WriteToFile(MyDir + 'test3.xls', sfExcel8, False);
MyWorkbook.WriteToFile(MyDir + 'test3.odt', sfOpenDocument, False); MyWorkbook.WriteToFile(MyDir + TestFile, sfOpenDocument, False);
MyWorkbook.Free; MyWorkbook.Free;
writeln('Finished. Please open "'+TestFile+'" in your spreadsheet program.');
end. end.

View File

@ -1,7 +1,7 @@
{ {
test_write_formula.pas test_write_formula.pas
Demonstrates how to write an formula using the fpspreadsheet library Demonstrates how to write a formula using the fpspreadsheet library
AUTHORS: Felipe Monteiro de Carvalho AUTHORS: Felipe Monteiro de Carvalho
} }
@ -84,7 +84,10 @@ begin
MyCell^.UsedFormattingFields := [uffBorder, uffBackgroundColor, uffBold];} MyCell^.UsedFormattingFields := [uffBorder, uffBackgroundColor, uffBold];}
end; end;
const
TestFile='test_formula.xls';
begin begin
writeln('Starting program.');
MyDir := ExtractFilePath(ParamStr(0)); MyDir := ExtractFilePath(ParamStr(0));
// Create the spreadsheet // Create the spreadsheet
@ -95,8 +98,9 @@ begin
WriteSecondWorksheet(); WriteSecondWorksheet();
// Save the spreadsheet to a file // Save the spreadsheet to a file
MyWorkbook.WriteToFile(MyDir + 'test_formula.xls', sfExcel8, True); MyWorkbook.WriteToFile(MyDir + TestFile, sfExcel8, True);
// MyWorkbook.WriteToFile(MyDir + 'test_formula.odt', sfOpenDocument, False); // MyWorkbook.WriteToFile(MyDir + 'test_formula.odt', sfOpenDocument, False);
MyWorkbook.Free; MyWorkbook.Free;
writeln('Finished. Please open "'+Testfile+'" in your spreadsheet program.');
end. end.