You would probably be better off with the newer command CPYTOIPMF but in either case what you create is an .csv file. Excel will open a .csv file using the comma’s as column delimiters.
Creating a .XLS file requires a lot more than just comma’s between the fields. There are a number of third party packages for this.
Note that sending a file through SMTP e-mail can require far more than simply copying the file to a /QDLS folder. If the file contains any bytes that are not simple text bytes, then the file can only be sent as a MIME attachment. And it’s likely that you’ll need to prepare it as a base64 encoded (or one of the other potentially appropriate encodings) file and also set the e-mail body to include the appropriate MIME headers that describe what the attachment is.
An actual Excel spreadsheet file is going to have lots of control codes and non-text bytes embedded within it.
SMTP cannot transfer bytes except those that are classified as “quoted printable”, basic ASCII text characters. That’s a fundamental restriction on how SMTP servers work. If you don’t follow SMTP rules, there’s no guarantee that the recipient will see a useful file.
Therefore, in order to send an attached file that has characters with hex values outside of that range, the file must be converted (encoded) into a form that uses only the valid characters. The most common form is BASE64 encoding.
You can create the encoded version yourself or you can install and use a product (or utility) that does it for you. Either way, you most likely will <b>not</b> be using CPYTOPCD anywhere in the process.