[Solved] Can it be used as an Excel database? lazarus / 16-Databases ---------------------------------------------------------------------- loaded · 2022-09-20 12:33 Hi All, Is there a method where we can query an open and active Excel list on the screen as if we were using a database (with SQL Sentences)? By the way, I provide the connection with Excel with GetActiveOleObject. I would be very grateful if you could share your knowledge and experience. ---------------------------------------------------------------------- rvk · 2022-09-20 13:13 Why do you want to use SQL? Or is it that you just want a TDataset? You could copy all content of a Excel (via GetOleObject) to a TClientDataSet (TBufDataset). And work with that. I'm not aware of a complete TDataSetProvider that directly works with an active object from GetOleObject. I'm also not sure what you actually want. You can also look into fpspreadsheet. ---------------------------------------------------------------------- Zvoni · 2022-09-20 13:48 Provided the OLE-DB-Provider is installed, you can use an ODBC- Connection This is my Connection-String i use in VBA to query an Excel-Workbook which has MACROS, though using ADODB in VBA (This is NOT Pascal- Syntax!) Beware of the double-quotes in there. For "Standard"-Excel (no macros) i'm letting you have a guess what has to be changed Code: [Select]ConString = "Provider=Microsoft.ACE.OLEDB.16.0;Data Source=""" & ThisWorkbook.FullName & """;Extended Properties=""Excel 12.0 Macro;HDR=Yes;IMEX=1"";" ---------------------------------------------------------------------- loaded · 2022-09-20 13:51 First of all thank you so much rvk and Zvoni for replying. Quote from: rvk on September 20, 2022, 03:13:08 pmI'm also not sure what you actually want. My workplace receives files in excel format from an official institution with the same schema but changing content, and I calculate the statistics of different information such as unique, similar, total and number in these files. It is not possible for me to ask for change from the other side. Quote from: rvk on September 20, 2022, 03:13:08 pmWhy do you want to use SQL? Or is it that you just want a TDataset? It is very easy to do the above operations in SQL, it is a little more problematic in Excel. For this reason  ; I wanted to reuse the Sql sentences in the Postgresql database that I am currently using, with a few minor changes. Quote from: Zvoni on September 20, 2022, 03:48:30 pmProvided the OLE- DB-Provider is installed, you can use an ODBC-Connection Code: [Select]ConString = "Provider=Microsoft.ACE.OLEDB.16.0;Data Source=""" & ThisWorkbook.FullName & """;Extended Properties=""Excel 12.0 Macro;HDR=Yes;IMEX=1"";" Yes this might work, thank you very much for the info. ---------------------------------------------------------------------- wp · 2022-09-20 13:52 Quote from: loaded on September 20, 2022, 02:33:40 pmHi All, Is there a method where we can query an open and active Excel list on the screen as if we were using a database (with SQL Sentences)? In fpspreadsheet, there is a TsWorksheetDataset which allows to access a spreadsheet like a database. No SQL, though. ---------------------------------------------------------------------- loaded · 2022-09-21 08:34 Thank you for your reply and additional information, wp ---------------------------------------------------------------------- heejit · 2022-10-31 04:31 You can use pl/python in Postgresql also not a FPC solution. ---------------------------------------------------------------------- loaded · 2022-10-31 05:07 Thank you very much for your reply my brother heejit. I had solved my problem. But I forgot to mention, sorry. Sometimes the best way is the old way. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button_ConnectClick(Sender: TObject);var    ExcelApp,ExcelApp_Book,ExcelApp_Sheet:OleVariant;begin  ExcelApp := GetActiveOleObject('Excel.Application');  ExcelApp_Book := ExcelApp.ActiveWorkBook;  ExcelApp_Sheet:=ExcelApp_Book.ActiveSheet;  ExcelApp_RowCount:=ExcelApp_Sheet.Usedrange.EntireRow.count;  ExcelApp_ColCount:=ExcelApp_Sheet.UsedRange.Columns.count;  //string(ExcelApp_Book.name +' [' +ExcelApp_Sheet.name+ ']');end; ---------------------------------------------------------------------- Nicole · 2022-10-31 11:21 I worked a lot with this OLE. Under the line: I did away with it. It is too - I do not know an English word for it, German "frickelig". You have to work in Excel and there you can do a wrong click. The cells move that quickly and without warning. The code was never robust quality. So my answer is, "if any different way is possible, - avoid it". Try hard to avoid it, it will not make you happy on long run. ---------------------------------------------------------------------- loaded · 2022-10-31 12:08 Thank you very much Nicole for your reply and warning. I've been experiencing the problem you mentioned from time to time. As a solution, I work with a single excel file as much as possible. Before working, I use the following code. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ExcelApp .Visible:=false; ---------------------------------------------------------------------- Thaddy · 2022-10-31 12:10 Translation is "prickly", "awkward" or "nasty". Even "cumbersome" would apply. I learned to avoid OLE like the plague since 1998...If possible use early binding. Then again: German is a rather strange dialect of Dutch.. ---------------------------------------------------------------------- loaded · 2022-10-31 13:03 Quote from: Thaddy on October 31, 2022, 01:10:34 pmIf possible use early binding. Thank you very much for the reply, Master Thaddy. Maybe I've been using ole for twelve years, I didn't know about such a thing. I learned something new today thanks to you. I hope one day I'll buy you all a cup of coffee in return for what I've learned. ---------------------------------------------------------------------- rvk · 2022-10-31 13:16 Quote from: loaded on October 31, 2022, 02:03:41 pmQuote from: Thaddy on October 31, 2022, 01:10:34 pmIf possible use early binding. Thank you very much for the reply, Master Thaddy. Maybe I've been using ole for twelve years, I didn't know about such a thing. Please note that your program won't run on systems without (offline-) Office installed when using early binding. That's why I avoid early binding at all cost  (My software also runs needs to run on systems with LibreOffice or even without an office-suit in which case cloud services could be used) ---------------------------------------------------------------------- loaded · 2022-10-31 13:55 Thank you very much for the information rvk In this forum, pearls are poured out as the masters speak. ---------------------------------------------------------------------- Nicole · 2022-10-31 16:45 ExcelApp .Visible:=false; This is a good idea! And a second point. If you enjoy the platform neutral Lazarus, you bind yourself to any Office and windows. Sure, if you have "working team" with Excel since decades, it is not a good idea to change anything. For me it is good to know: I am free to change to Linux every time. That I will not do it, because I am afraid, I am quite happy with the functionality of Windows, this is a different topic.