If the OS is 64 bit (which it usually is these days) then MS Office could be 32 bit or 64 bit (it's often still 32 bit) and Delphi apps could be either as well and if your Delphi app's bitness doesn't match that of Office your automation might fail. You've now touched on a touchy subject in respect of "bitness". Thanks again for explaining the Excel approach with Delphi in a simple way and for the really good Delphi blog.ĭonald Klopper at 11:39 that's why I posted my ideas in the comments as well. Unfortunately I will not be able to apply the same solution with Delphi 7 because it does not have a 64-bit target, but I am happy to have solved the problem. So I tried to change the Delphi target, from WIN32 to WIN64, in Berlin version of the project and recompiled it, without changing anything and. Looking for "EOleSysError" online, I found that one of the possible causes is access to a 64 bit server (my Excel) with a 32 bit module (my Delphi application). I couldn't understand where the mistake was. "Įrror #2: "Access violation at address 006695C6 in module 'ExcelTest.exe'. OpenFileName := FileOpenDialog1.FileName Procedure TForm1.OpenExcelFileClick(Sender: TObject) ĭisplayName := 'Excel files (*.xlsx *.xls)' įileOpenDialog1.Title := 'Select file to open' Procedure OpenExcelFileClick(Sender: TObject) Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Excel2010, Vcl.StdCtrls, Vcl.Grids Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, #DELPHI READ EXCEL FILE CODE#The code that I have written as the test is: The crash is at function TExcelApplication.GetDefaultInterface: _Application, at the first line: The crash occurs in Excel_TLB.pas, which I imported as Donald Klopper suggested. Has anyone else had this and been able to solve it? I get an exception class $C00000005 error with access violation at Oxoo62fd0b: read of address 0x000001bc when I use Workbooks.Open. Write additional code to address as desired.I have been trying to read from Excel and used this information as the basis for a test program. Note: If a file with the new name already exists, it overwrites it. If VarIsNull(ExcelWorksheet) = False thenĮxcelWorksheet.Cells := 'We just created a new Excel file with one worksheet!' //, in this case, text is added to Cell A1Į //selects Cell A2 connect to Excel Worksheet using either the ExcelApplication or ExcelWorkbook handleĮxcelWorksheet := ExcelWorkbook.WorkSheets // specifies the first worksheet May be helpful to set to True during testing and debugging.ĮxcelWorkbook := (- 4167) If VarIsNull(ExcelApplication) = False thenĮxcelApplication.Visible := True //set to False if you do not want to see the activity in the backgroundĮxcelApplication.DisplayAlerts := False //ensures message dialogs do not interrupt the flow of your automation process. add error/exception handling code as desired be sure ComObj and Variants units are included in the "uses" clauseĮxcelFileName := 'C:\PhysiologyWeb\delphi_code_examples\new_excel_file.xlsx' //replace file name with the name of your fileĮxcelApplication := CreateOleObject( 'Excel.Application') Procedure TForm1.OpenANewExcelFileAndSave(Sender: TObject) ĮxcelApplication, ExcelWorkbook, ExcelWorksheet: Variant
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |