Categories > OpenTBS with XLSX >

How to attach xlsx to email

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Antanas
Date: 2016-04-13
Time: 16:22

How to attach xlsx to email

Hello,

I was trying to send xlsx file by email by using these approach:

$TBS->Show(TBS_NOTHING);
$xls_content = $TBS->Source;

$mail->addAttachment(new stringAttachment($xls_content, "test.xlsx", 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'));

The problem is - generated email attachment test.xlsx contains only sheet.xml inside. If I open it by notepad I see plain xml data:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"....

There is no zip content as it should be for xlsx.

However if I choose to download it instead of streaming to email:
$TBS->Show(OPENTBS_DOWNLOAD, $output_file_name);

It downloads correct xlsx file.

So how can I make a full (zipped xlsx) attachment?
By: Antanas
Date: 2016-04-14
Time: 08:32

Re: How to attach xlsx to email

Never mind - I figured out it by myself :)
It should be OPENTBS_STRING as a parameter for Show():

$TBS->Show(OPENTBS_STRING);
$xls_content = $TBS->Source;

$mail->addAttachment(new stringAttachment($xls_content, "test.xlsx", 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'));

That way it generates the right XLSX attachment.
Thank you anyway. OpenTBS is awesome!