how to write a xls file use wps CreateOleObject KetApplication in delphi
To write a XLS file using WPS CreateOleObject Ket.Application in Delphi, you can follow these steps:
- Open Delphi and create a new project.
- Add a button to the form.
- Double-click on the button to create an OnClick event handler.
- In the event handler, add the following code:
var
Excel: OleVariant;
begin
Excel := CreateOleObject('Ket.Application');
Excel.Visible := True;
Excel.Workbooks.Add;
Excel.Worksheets[1].Cells[1,1] := 'Hello World!';
Excel.ActiveWorkbook.SaveAs('C:\example.xls', 56);
Excel.Quit;
end;
- This code will create a new instance of Excel using the CreateOleObject function. It will then make the Excel window visible and create a new workbook. It will then write the text "Hello World!" to cell A1 of the first worksheet. Finally, it will save the workbook to a file called "example.xls" on the C: drive and quit Excel.
Note: The number 56 in the SaveAs function represents the file format for XLS. You can find a list of file format codes in the Excel documentation
原文地址: https://www.cveoy.top/t/topic/dHV8 著作权归作者所有。请勿转载和采集!