Recent

Author Topic: Execute ( open ) an 'xlsx f'ile.  (Read 906 times)

seghele0

  • Sr. Member
  • ****
  • Posts: 253
Execute ( open ) an 'xlsx f'ile.
« on: May 21, 2023, 03:40:02 pm »
Windows 11 + Lazarus.
Can someone provide the code to open an 'xlsx' file by using a Button. The xlsx file is already in the same folder as the application.
Thanks already.

RayoGlauco

  • Full Member
  • ***
  • Posts: 194
  • Beers: 1567
Re: Execute ( open ) an 'xlsx f'ile.
« Reply #1 on: May 21, 2023, 03:46:58 pm »
There is a multiplatform function that opens documents:

Code: Pascal  [Select][+][-]
  1.  
  2. // function OpenDocument(APath: String): Boolean;
  3.  
  4. uses
  5.   LCLIntf;
  6.  
  7. ...
  8. if OpenDocument('file.xlsx') then ...
  9.  
  10.  
To err is human, but to really mess things up, you need a computer.

jamie

  • Hero Member
  • *****
  • Posts: 6798
Re: Execute ( open ) an 'xlsx f'ile.
« Reply #2 on: May 21, 2023, 03:50:26 pm »
https://wiki.freepascal.org/FPSpreadsheet

that will support it and most likely has the code visible for you to look at it.
The only true wisdom is knowing you know nothing

seghele0

  • Sr. Member
  • ****
  • Posts: 253
Re: Execute ( open ) an 'xlsx f'ile.
« Reply #3 on: May 21, 2023, 05:09:42 pm »
Thanks for the reply.
 :-\
My knowledge of Pascal is limited, and my programming ability is limited.
A simple working example would be ideal.
Just a button on an empty application that opens the 'xlsx'.
Tks.

TRon

  • Hero Member
  • *****
  • Posts: 3925
Re: Execute ( open ) an 'xlsx f'ile.
« Reply #4 on: May 21, 2023, 05:17:38 pm »
Perfect question for an AI:

Q: make a form with a button that when pressed opens a xlsx file using the opendocument function

Creating a Form with a Button to Open an XLSX File in Lazarus

Requirement Summary

The task at hand is to create a form in Lazarus that contains a button. When the button is pressed, it should open an XLSX file using the opendocument function. This can be achieved by following the steps outlined below.

Code Generated

To begin, we need to create a new project in Lazarus. Once the project is created, we can start designing the form. We will need to add a button to the form, which can be done by dragging and dropping a TButton component from the Component Palette onto the form.

Next, we need to add an event handler for the button. This can be done by double-clicking on the button in the form designer. This will open the code editor and create a new event handler for the OnClick event of the button.

In the event handler, we can use the opendocument function to open the XLSX file. The opendocument function is part of the LazFileUtils unit, so we need to add this unit to our uses clause at the top of the code editor.

Here is an example of what the code for the event handler might look like:

Code: Pascal  [Select][+][-]
  1. uses
  2.   LazFileUtils;
  3.  
  4. procedure TForm1.Button1Click(Sender: TObject);
  5. begin
  6.   OpenDocument('path/to/file.xlsx');
  7. end;
  8.  

In this example, we are calling the OpenDocument function with the path to the XLSX file as a parameter. When the button is clicked, the opendocument function will be called and the XLSX file will be opened.

It is important to note that the path to the XLSX file should be an absolute path, not a relative path. This means that the full path to the file should be specified, including the drive letter (e.g. C:\path\to\file.xlsx).

Once the code is written, we can save the project and run it. When the form is displayed, we can click the button to open the XLSX file.

In conclusion, creating a form with a button to open an XLSX file in Lazarus is a simple task that can be accomplished by following the steps outlined above. By using the opendocument function and adding an event handler for the button, we can create a functional application that meets the requirements of the task.
I do not have to remember anything anymore thanks to total-recall.

seghele0

  • Sr. Member
  • ****
  • Posts: 253
Re: Execute ( open ) an 'xlsx f'ile.
« Reply #5 on: May 21, 2023, 05:59:19 pm »
Wonderful, it works.
THANK YOU.
 ;)

 

TinyPortal © 2005-2018