diff --git a/components/fpspreadsheet/examples/other/conditional_formatting/demo_conditional_formatting.pas b/components/fpspreadsheet/examples/other/conditional_formatting/demo_conditional_formatting.pas
index 04d903802..bd25bac2a 100644
--- a/components/fpspreadsheet/examples/other/conditional_formatting/demo_conditional_formatting.pas
+++ b/components/fpspreadsheet/examples/other/conditional_formatting/demo_conditional_formatting.pas
@@ -13,6 +13,8 @@ var
row: Integer;
i: Integer;
lastCol: Integer;
+ dir: String;
+
begin
wb := TsWorkbook.Create;
try
@@ -397,9 +399,10 @@ begin
sh.WriteIconSet(Range(Row, 2, row, 12), is3Flags);
{ ------ Save workbook to file-------------------------------------------- }
- wb.WriteToFile('test.xlsx', true);
- wb.WriteToFile('test.ods', true);
- wb.WriteToFile('test.xml', true);
+ dir := ExtractFilePath(ParamStr(0));
+ wb.WriteToFile(dir + 'test.xlsx', true);
+ wb.WriteToFile(dir + 'test.ods', true);
+ wb.WriteToFile(dir + 'test.xml', true);
if wb.ErrorMsg <> '' then
WriteLn(wb.ErrorMsg);
diff --git a/components/fpspreadsheet/examples/read_write/hyperlinkdemo/collectlinks.lpi b/components/fpspreadsheet/examples/other/hyperlinkdemo/collectlinks.lpi
similarity index 100%
rename from components/fpspreadsheet/examples/read_write/hyperlinkdemo/collectlinks.lpi
rename to components/fpspreadsheet/examples/other/hyperlinkdemo/collectlinks.lpi
diff --git a/components/fpspreadsheet/examples/read_write/hyperlinkdemo/collectlinks.lpr b/components/fpspreadsheet/examples/other/hyperlinkdemo/collectlinks.lpr
similarity index 87%
rename from components/fpspreadsheet/examples/read_write/hyperlinkdemo/collectlinks.lpr
rename to components/fpspreadsheet/examples/other/hyperlinkdemo/collectlinks.lpr
index c67ee50dd..3a67dc6a9 100644
--- a/components/fpspreadsheet/examples/read_write/hyperlinkdemo/collectlinks.lpr
+++ b/components/fpspreadsheet/examples/other/hyperlinkdemo/collectlinks.lpr
@@ -28,21 +28,24 @@ var
sheetFormat: TsSpreadsheetFormat;
sheetName: String;
r, c: Cardinal;
+ dir: String;
begin
// Just for the demo: create the file "source.xls". It contains hyperlinks to
// some of the "test" files created in the XXXXdemo projects
Write('Creating source workbook...');
+ dir := ExtractFilePath(ParamStr(0));
+
srcWorkbook := TsWorkbook.Create;
try
sheet := srcWorkbook.AddWorksheet('Sheet');
sheet.WriteText(0, 0, 'Link to biff8 test file');
- sheet.WriteHyperlink(0, 0, '../excel8demo/test.xls#''My Worksheet 2''!A1');
+ sheet.WriteHyperlink(0, 0, '../../read_write/excel8demo/test.xls#''My Worksheet 2''!A1');
//sheet.WriteHyperlink(0, 0, '../excel8demo/test.xls#''Meu Relatório''!A1');
sheet.WriteText(1, 0, 'Link to ods test file');
- sheet.WriteHyperlink(1, 0, '..\opendocdemo\test.ods');
+ sheet.WriteHyperlink(1, 0, '../../read_write/opendocdemo/test.ods');
sheet.WriteText(2, 0, 'E-Mail Link');
sheet.WriteHyperlink(2, 0, 'mailto:someone@mail.com;someoneelse@mail.com?Subject=This is a test');
@@ -51,7 +54,7 @@ begin
sheet.WriteHyperlink(3, 0, 'http://www.lazarus-ide.org/');
sheet.WriteText(4, 0, 'File-Link (absolute path)');
- sheet.WriteHyperlink(4, 0, 'file:///'+ExpandFilename('..\..\..\tests\testooxml_1899.xlsx'));
+ sheet.WriteHyperlink(4, 0, 'file:///'+ExpandFilename('../../../tests/testooxml_1899.xlsx'));
// This creates the URI such as "file:///D:\Prog_Lazarus\svn\lazarus-ccr\components\fpspreadsheet\tests\testooxml_1899.xlsx"
// but makes sure that the file exists on your system.
@@ -60,7 +63,7 @@ begin
sheet.WriteColWidth(0, 40, suChars);
- srcWorkbook.WriteToFile(srcFile, true);
+ srcWorkbook.WriteToFile(dir + srcFile, true);
finally
srcWorkbook.Free;
end;
@@ -73,7 +76,7 @@ begin
Write('Reading source workbook, sheet ');
srcWorkbook := TsWorkbook.Create;
try
- srcWorkbook.ReadFromFile(srcFile);
+ srcWorkbook.ReadFromFile(dir + srcFile);
sheet := srcWorkbook.GetWorksheetByIndex(0);
WriteLn(sheet.Name, '...');
@@ -125,7 +128,7 @@ begin
continue;
end;
// Copy linked worksheet to new sheet in destination workbook
- destSheet := destWorkbook.CopyWorksheetFrom(linkedSheet);
+ destSheet := destWorkbook.CopyWorksheetFrom(linkedSheet, true);
// Create sheet name
sheetName := ExtractFileName(fn) + '#' +linkedSheet.Name;
destWorkbook.ValidWorksheetName(sheetName, true);
@@ -144,24 +147,27 @@ begin
WriteLn;
if destWorkbook <> nil then
begin
- destworkbook.WriteToFile(destFile+'.xls', true);
- destworkbook.WriteToFile(destFile+'.xlsx', true);
- destworkbook.WriteToFile(destFile+'.ods', true);
+ destworkbook.WriteToFile(dir + destFile+'.xls', true);
+ destworkbook.WriteToFile(dir + destFile+'.xlsx', true);
+ destworkbook.WriteToFile(dir + destFile+'.ods', true);
WriteLn('All hyperlinks to spreadsheets are collected in files ' + destFile + '.*');
end else
WriteLn('No hyperlinks found.');
- {$IFDEF Windows}
- WriteLn;
- WriteLn('Press ENTER to close...');
- ReadLn;
- {$ENDIF}
-
finally
// Clean up
srcWorkbook.Free;
if destWorkbook <> nil then destWorkbook.Free;
end;
+ if ParamCount = 0 then
+ begin
+ {$IFDEF MSWindows}
+ WriteLn;
+ WriteLn('Press ENTER to close...');
+ ReadLn;
+ {$ENDIF}
+ end;
+
end.
diff --git a/components/fpspreadsheet/examples/read_write/hyperlinkdemo/readme.txt b/components/fpspreadsheet/examples/other/hyperlinkdemo/readme.txt
similarity index 100%
rename from components/fpspreadsheet/examples/read_write/hyperlinkdemo/readme.txt
rename to components/fpspreadsheet/examples/other/hyperlinkdemo/readme.txt
diff --git a/components/fpspreadsheet/examples/other/ignore_formulas/demo_ignore_formula.lpr b/components/fpspreadsheet/examples/other/ignore_formulas/demo_ignore_formula.lpr
index 5c01752b2..e4429c249 100644
--- a/components/fpspreadsheet/examples/other/ignore_formulas/demo_ignore_formula.lpr
+++ b/components/fpspreadsheet/examples/other/ignore_formulas/demo_ignore_formula.lpr
@@ -40,6 +40,7 @@ var
book: TsWorkbook;
sheet: TsWorksheet;
cell: PCell;
+ dir: String;
// example for an external ods reference:
// ='file:///D:/fpspreadsheet/examples/other/external.ods'#$Sheet.A1
@@ -79,6 +80,8 @@ var
end;
begin
+ dir := ExtractFilePath(ParamStr(0));
+
// Write external file
book := TsWorkbook.Create;
try
@@ -90,7 +93,7 @@ begin
cell := sheet.GetCell(CELL2);
sheet.WriteText(cell, 'Hallo');
- book.WriteToFile(EXTERNAL_FILE, FILE_FORMAT, true);
+ book.WriteToFile(dir+EXTERNAL_FILE, FILE_FORMAT, true);
finally
book.Free;
end;
@@ -103,9 +106,9 @@ begin
sheet := book.AddWorksheet('Sheet');
// Write external references
- sheet.WriteFormula(0, 0, ExtRef(EXTERNAL_FILE, EXTERNAL_SHEET, CELL1));
- sheet.WriteFormula(1, 0, ExtRef(EXTERNAL_FILE, EXTERNAL_SHEET, CELL2));
- book.WriteToFile(MASTER_FILE, FILE_FORMAT, true);
+ sheet.WriteFormula(0, 0, ExtRef(dir + EXTERNAL_FILE, EXTERNAL_SHEET, CELL1));
+ sheet.WriteFormula(1, 0, ExtRef(dir + EXTERNAL_FILE, EXTERNAL_SHEET, CELL2));
+ book.WriteToFile(dir + MASTER_FILE, FILE_FORMAT, true);
finally
book.Free;
diff --git a/components/fpspreadsheet/examples/other/metadata/demo_metadata.lpr b/components/fpspreadsheet/examples/other/metadata/demo_metadata.lpr
index 0c66ef1fe..99de02103 100644
--- a/components/fpspreadsheet/examples/other/metadata/demo_metadata.lpr
+++ b/components/fpspreadsheet/examples/other/metadata/demo_metadata.lpr
@@ -59,7 +59,10 @@ var
book: TsWorkbook;
sheet: TsWorksheet;
i: Integer;
+ dir: String;
begin
+ dir := ExtractFilePath(ParamStr(0));
+
book := TsWorkbook.Create;
try
book.MetaData.CreatedBy := 'Donald Duck & Dagobert Duck';
@@ -80,9 +83,9 @@ begin
sheet := book.AddWorksheet('Test');
sheet.WriteText(2, 3, 'abc');
sheet.WriteBackgroundColor(2, 3, scYellow);
- book.WriteToFile('test.xlsx', true);
- book.WriteToFile('test.ods', true);
- book.WriteToFile('test.xml', true)
+ book.WriteToFile(dir + 'test.xlsx', true);
+ book.WriteToFile(dir + 'test.ods', true);
+ book.WriteToFile(dir + 'test.xml', true)
finally
book.Free;
end;
diff --git a/components/fpspreadsheet/examples/other/other_demos.lpg b/components/fpspreadsheet/examples/other/other_demos.lpg
index 0dedbbf6c..7cc585fdf 100644
--- a/components/fpspreadsheet/examples/other/other_demos.lpg
+++ b/components/fpspreadsheet/examples/other/other_demos.lpg
@@ -27,6 +27,11 @@
+
+
+
+
+
diff --git a/components/fpspreadsheet/examples/other/protection/demo_protection.pas b/components/fpspreadsheet/examples/other/protection/demo_protection.pas
index de109efa2..86bcfa392 100644
--- a/components/fpspreadsheet/examples/other/protection/demo_protection.pas
+++ b/components/fpspreadsheet/examples/other/protection/demo_protection.pas
@@ -14,6 +14,8 @@ var
sheet: TsWorksheet;
cell: PCell;
c: TsCryptoInfo;
+ dir: String;
+
begin
book := TsWorkbook.Create;
try
@@ -35,10 +37,11 @@ begin
sheet.Protection := [spDeleteRows, spDeleteColumns, spInsertRows, spInsertColumns];
sheet.Protect(true);
- book.WriteToFile('protected.xls', sfExcel8, true);
- book.WriteToFile('protected.xlsx', sfOOXML, true);
+ dir := ExtractFilePath(ParamStr(0));
+ book.WriteToFile(dir + 'protected.xls', sfExcel8, true);
+ book.WriteToFile(dir + 'protected.xlsx', sfOOXML, true);
// Note ODS does not write the excel password correctly, yet. --> protection cannot be removed.
- book.WriteToFile('protected.ods', sfOpenDocument, true);
+ book.WriteToFile(dir + 'protected.ods', sfOpenDocument, true);
finally
book.Free;
diff --git a/components/fpspreadsheet/examples/other/recursive_calculation/demo_recursive_calc.pas b/components/fpspreadsheet/examples/other/recursive_calculation/demo_recursive_calc.pas
index 7952c676b..63fe56e1f 100644
--- a/components/fpspreadsheet/examples/other/recursive_calculation/demo_recursive_calc.pas
+++ b/components/fpspreadsheet/examples/other/recursive_calculation/demo_recursive_calc.pas
@@ -14,17 +14,21 @@ uses
cthreads,
{$ENDIF}
{$ENDIF}
- Classes, Math,
+ SysUtils, Classes, Math,
fpstypes, fpspreadsheet, fpsfunc, xlsbiff8;
var
workbook: TsWorkbook;
worksheet: TsWorksheet;
+ dir: String;
+
const
- OutputFile='test_recursive.xls';
+ OutputFile = 'test_recursive.xls';
begin
writeln('Starting program.');
+
+ dir := ExtractFilePath(ParamStr(0));
workbook := TsWorkbook.Create;
try
workbook.Options := workbook.Options + [boCalcBeforeSaving];
@@ -39,10 +43,10 @@ begin
worksheet.WriteUTF8Text(2, 0, '(not dependent)'); // A3
worksheet.WriteNumber(2, 1, 1); // B3
- workbook.WriteToFile(OutputFile, sfExcel8, true);
+ workbook.WriteToFile(dir + OutputFile, sfExcel8, true);
writeln('Finished.');
writeln;
- writeln('Please open "'+OutputFile+'" in "fpsgrid".');
+ writeln('Please open "'+dir+OutputFile+'" in "fpsgrid".');
writeLn('It must show correct calculation results in cells B1 and B2.');
finally
diff --git a/components/fpspreadsheet/examples/other/run_all_demos.bat b/components/fpspreadsheet/examples/other/run_all_demos.bat
index e9c7adaed..8db0f94d2 100644
--- a/components/fpspreadsheet/examples/other/run_all_demos.bat
+++ b/components/fpspreadsheet/examples/other/run_all_demos.bat
@@ -3,6 +3,7 @@ colors\demo_write_colors -quit
conditional_formatting\demo_conditional_formatting -quit
expression_parser\demo_expression_parser -quit
header_footer_images\demo_write_headerfooter_images -quit
+hyperlinkdemo\collectlinks -quit
ignore_formulas\demo_ignore_formula -quit
images\demo_write_images -quit
metadata\demo_metadata -quit
diff --git a/components/fpspreadsheet/examples/other/user_defined_formulas/demo_formula_func.pas b/components/fpspreadsheet/examples/other/user_defined_formulas/demo_formula_func.pas
index 44cbb5998..4f90730ff 100644
--- a/components/fpspreadsheet/examples/other/user_defined_formulas/demo_formula_func.pas
+++ b/components/fpspreadsheet/examples/other/user_defined_formulas/demo_formula_func.pas
@@ -295,13 +295,17 @@ const
TestFile='test_user_formula.xlsx'; // Format depends on extension selected
// !!!! ods not working yet !!!!
+var
+ dir: String;
+
begin
WriteLn('This demo registers user-defined functions for financial calculations');
WriteLn('and writes and reads the corresponding spreadsheet file.');
WriteLn;
- WriteFile(TestFile);
- ReadFile(TestFile);
+ dir := ExtractFilePath(ParamStr(0));
+ WriteFile(dir + TestFile);
+ ReadFile(dir + TestFile);
WriteLn;
WriteLn('Open the file in Excel or OpenOffice/LibreOffice.');
diff --git a/components/fpspreadsheet/examples/other/virtual_mode/demo_virtualmode_read.lpr b/components/fpspreadsheet/examples/other/virtual_mode/demo_virtualmode_read.lpr
index d46d42618..344ec6302 100644
--- a/components/fpspreadsheet/examples/other/virtual_mode/demo_virtualmode_read.lpr
+++ b/components/fpspreadsheet/examples/other/virtual_mode/demo_virtualmode_read.lpr
@@ -27,6 +27,7 @@ var
worksheet: TsWorksheet;
dataAnalyzer: TDataAnalyzer;
t: TTime;
+ dir: String;
procedure TDataAnalyzer.ReadCellDataHandler(Sender: TObject;
ARow, ACol: Cardinal; const ADataCell: PCell);
@@ -47,7 +48,9 @@ var
end;
begin
- if not FileExists(TestFileName) then begin
+ dir := ExtractFilePath(ParamStr(0));
+
+ if not FileExists(dir + TestFileName) then begin
WriteLn('The test file does not exist. Please run demo_virtual_write first.');
Halt;
end;
@@ -68,7 +71,7 @@ begin
workbook.OnReadCellData := @dataAnalyzer.ReadCellDataHandler;
t := Now;
- workbook.ReadFromFile(TestFileName);
+ workbook.ReadFromFile(dir + TestFileName);
t := Now - t;
WriteLn(Format('The workbook containes %d number and %d label cells, total %d.', [
diff --git a/components/fpspreadsheet/examples/other/virtual_mode/demo_virtualmode_write.lpr b/components/fpspreadsheet/examples/other/virtual_mode/demo_virtualmode_write.lpr
index 34711497a..86cfd5060 100644
--- a/components/fpspreadsheet/examples/other/virtual_mode/demo_virtualmode_write.lpr
+++ b/components/fpspreadsheet/examples/other/virtual_mode/demo_virtualmode_write.lpr
@@ -57,7 +57,11 @@ var
WriteLn('Writing row ', ARow, '...');
end;
+var
+ dir: String;
begin
+ dir := ExtractFilePath(ParamStr(0));
+
dataprovider := TDataProvider.Create;
try
workbook := TsWorkbook.Create;
@@ -98,11 +102,11 @@ begin
{ In case of a database, you would open the dataset before calling this: }
t := Now;
- //workbook.WriteToFile('test_virtual.ods', sfOpenDocument, true);
- //workbook.WriteToFile('test_virtual.xlsx', sfOOXML, true);
- workbook.WriteToFile('test_virtual.xls', sfExcel8, true);
- //workbook.WriteToFile('test_virtual.xls', sfExcel5, true);
- //workbook.WriteToFile('test_virtual.xls', sfExcel2, true);
+ //workbook.WriteToFile(dir + 'test_virtual.ods', sfOpenDocument, true);
+ //workbook.WriteToFile(dir + 'test_virtual.xlsx', sfOOXML, true);
+ workbook.WriteToFile(dir + 'test_virtual.xls', sfExcel8, true);
+ //workbook.WriteToFile(dir + 'test_virtual.xls', sfExcel5, true);
+ //workbook.WriteToFile(dir + 'test_virtual.xls', sfExcel2, true);
t := Now - t;
finally
diff --git a/components/fpspreadsheet/examples/read_write/opendocdemo/opendocwrite.lpr b/components/fpspreadsheet/examples/read_write/opendocdemo/opendocwrite.lpr
index fe7f59789..f86ab71b7 100644
--- a/components/fpspreadsheet/examples/read_write/opendocdemo/opendocwrite.lpr
+++ b/components/fpspreadsheet/examples/read_write/opendocdemo/opendocwrite.lpr
@@ -282,7 +282,7 @@ begin
MyWorksheet := MyWorkbook.AddWorksheet('My Worksheet 2');
// Save the spreadsheet to a file
- MyWorkbook.WriteToFile(MyDir + 'test1.ods', sfOpenDocument, true);
+ MyWorkbook.WriteToFile(MyDir + 'test.ods', sfOpenDocument, true);
MyWorkbook.Free;
end.