Recent

Author Topic: ShellApi in Lazarus.  (Read 1219 times)

seghele0

  • Jr. Member
  • **
  • Posts: 84
ShellApi in Lazarus.
« on: November 23, 2021, 03:47:12 pm »
The procedure below works well.
But I would also like to activate the *.xlsx file, which is located in the folder of my exe program, to run either Excel or LibreOffice-Calc.
Van you please provide an example with the code?

Code: Pascal  [Select][+][-]
  1. procedure TFmain.MenuItemExportXLSXClick(Sender: TObject);
  2. var
  3.   varWorkbook: TsWorkbook;
  4.   varWorksheet: TsWorksheet;
  5.   varR, varC: Integer;
  6.   varFilename: String;
  7. begin
  8.   // Create a workbook
  9.   varWorkbook := TsWorkbook.Create;
  10.   try
  11.    try
  12.     // Add a worksheet to the workbook
  13.     varWorksheet := varWorkbook.AddWorksheet('Export-Wiezen ');
  14.     // Write the title row
  15.     for varC := 0 to StringGrid1.ColCount-1 do
  16.       varWorksheet.WriteText(0, varC, StringGrid1.Cells[varC, 0]);
  17.     // Write the data cells
  18.     for varR := 1 to StringGrid1.RowCount-1 do
  19.     begin
  20.       for varC := 0 to StringGrid1.ColCount-1 do
  21.         case varC of
  22.           //0: TEKST
  23.           0: varWorksheet.WriteText(varR, varC, StringGrid1.Cells[varC, varR]);
  24.           //1:  CIJFERS
  25.           1: varWorksheet.WriteText(varR, varC, StringGrid1.Cells[varC, varR]);
  26.           //2:  CIJFERS
  27.           2: varWorksheet.WriteText(varR, varC, StringGrid1.Cells[varC, varR]);
  28.           //3:  CIJFERS
  29.           3: varWorksheet.WriteText(varR, varC, StringGrid1.Cells[varC, varR]);
  30.           //4:  CIJFERS
  31.           4: varWorksheet.WriteText(varR, varC, StringGrid1.Cells[varC, varR]);
  32.         end;
  33.     end;
  34.     varFilename := 'Wiezen-'+FormatDateTime('yyyy-mm-dd__hh.mm', now)+'.xlsx';
  35.     varWorkbook.WriteToFile(varFilename, sfOOXML, true);
  36.  
  37.   //// ShellExecute(0, 'open', PChar(), 'varFilename', '', SW_SHOWNORMAL);
  38.  
  39.   except
  40.     On E: Exception do
  41.     begin
  42.       Showmessage(E.Message);
  43.     end;
  44.   end;
  45.   finally
  46.     XLSXproc;   // Eigen procedure:('EXPORT naar XLSX bestand is voldaan! ');
  47.     // Destroy the workbook after usage.
  48.     varWorkbook.Free;
  49.   end;
  50. end;  
  51.  
In uses:
Code: Pascal  [Select][+][-]
  1. uses
  2.   Windows,
  3.   Dialogs, Interfaces, Classes, SysUtils, FileUtil, Forms,
  4.   Controls, ExtCtrls, StdCtrls, ComCtrls, Graphics, Menus,
  5.   Grids, Buttons, IniFiles, StrUtils, Printers, OSPrinters, Variants,
  6.   lMessages, LCLIntf, LCLProc, LCLType,
  7.   fpSpreadsheet, fpsTypes, xlsxOOXML, fpsexport;            
Do I need: Process or  ShellApi ?
 ::)

 

lainz

  • Hero Member
  • *****
  • Posts: 3874
Re: ShellApi in Lazarus.
« Reply #1 on: November 23, 2021, 04:05:14 pm »

seghele0

  • Jr. Member
  • **
  • Posts: 84
Re: ShellApi in Lazarus.
« Reply #2 on: November 23, 2021, 04:44:23 pm »
 :)
Thank you.
It's working fine.

seghele0

  • Jr. Member
  • **
  • Posts: 84
Re: ShellApi in Lazarus.
« Reply #3 on: November 24, 2021, 04:02:14 pm »
 :(
I should have written: works fine in Windows 11.

When I use the program in Linux and open via 'wine' then the function "opendocument" doesn't work.
All the rest of the program still works in Linux with "wine".
 :-[



Zvoni

  • Hero Member
  • *****
  • Posts: 807
Re: ShellApi in Lazarus.
« Reply #4 on: November 24, 2021, 04:26:20 pm »
I'm not even going to ask, why you run a Lazarus-Program under Wine......

Your call to opendocument fails, BECAUSE you are running it under wine
https://wiki.winehq.org/FAQ#How_do_I_associate_a_native_program_with_a_file_type_in_Wine.3F
You have to associate the default native Linux-Program to the File-Extension in wine
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

seghele0

  • Jr. Member
  • **
  • Posts: 84
Re: ShellApi in Lazarus.
« Reply #5 on: November 24, 2021, 04:49:17 pm »
In addition to Windows, I also have Linux Mint on my PC.
My son only uses Linux Mint.
On my pc, Lazarus only runs in Windows so I can use an "exe" in Linux too.
 8)
Your solution is too complex for my brain.



Handoko

  • Hero Member
  • *****
  • Posts: 4382
  • My goal: build my own game engine using Lazarus
Re: ShellApi in Lazarus.
« Reply #6 on: November 24, 2021, 04:54:05 pm »
In case if haven't known, Lazarus can be installed and run on Linux too.  :D

Zvoni

  • Hero Member
  • *****
  • Posts: 807
Re: ShellApi in Lazarus.
« Reply #7 on: November 24, 2021, 05:09:20 pm »
In addition to Windows, I also have Linux Mint on my PC.
My son only uses Linux Mint.
On my pc, Lazarus only runs in Windows so I can use an "exe" in Linux too.
 8)
Your solution is too complex for my brain.



Crosscompile to Linux-Target?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

seghele0

  • Jr. Member
  • **
  • Posts: 84
Re: ShellApi in Lazarus.
« Reply #8 on: November 24, 2021, 05:42:12 pm »
Thank you for the info.
 ;)
Why the same program compiling, in Windows and in Linux?
Wine is a good solution to use any Windows program (exe), but wine may still need to be updated!
This is a work for advanced programmers.

Handoko

  • Hero Member
  • *****
  • Posts: 4382
  • My goal: build my own game engine using Lazarus
Re: ShellApi in Lazarus.
« Reply #9 on: November 24, 2021, 05:48:52 pm »
I do not frequently try my programs to run on both Linux and Wine. But I can roughly say the cross compiled Windows versions (cross compiled from Linux) are about 30% behave (a bit) weird running on Wine, but they run perfectly as I wanted if I tried them on Win7/XP virtual machine.

Zvoni

  • Hero Member
  • *****
  • Posts: 807
Re: ShellApi in Lazarus.
« Reply #10 on: November 25, 2021, 09:34:27 am »
Thank you for the info.
 ;)
Why the same program compiling, in Windows and in Linux?
Wine is a good solution to use any Windows program (exe), but wine may still need to be updated!
This is a work for advanced programmers.
And as you just experienced, it's NOT!
scientific principle: A statement is proven wrong, if there is only one piece of counter-evidence
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

seghele0

  • Jr. Member
  • **
  • Posts: 84
Re: ShellApi in Lazarus.
« Reply #11 on: November 25, 2021, 09:45:53 am »
Thank you all for your intervention.
Maybe 'wine' isn't yet fully adapted to Windows 11 about function "opendocument".
 ;)

Zvoni

  • Hero Member
  • *****
  • Posts: 807
Re: ShellApi in Lazarus.
« Reply #12 on: November 25, 2021, 10:54:46 am »
It's got nothing to do with Windows 11
Wine doesn't know which native Programs are installed on your Linux-Box
Wine doesn't know, that a PDF should be opened with this and that NATIVE Linux-Program
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

seghele0

  • Jr. Member
  • **
  • Posts: 84
Re: ShellApi in Lazarus.
« Reply #13 on: November 25, 2021, 11:00:17 am »
OK.
 :-X

 

TinyPortal © 2005-2018