Email with Excel file Attached without prompting


I’m sending emails from Ignition with a xls file attached using the system.dataset.exportExcel function.

Here’s my script :

filePath=system.dataset.exportExcel("File.xls", 1, data)
if filePath != None:
   fileName = filePath.split("\\")[-1]
   fileData = system.file.readFileAsBytes(filePath)"smtp.example","","Subject","Body",0,[""],[fileName],[fileData])

I’d like to do the same thing but without prompting the user on where to save the file, just as I’m doing with the printToImage function which automatically saves the file in a temp folder and let me access it through its name rather than its path.

Example :

window = system.gui.getWindow("WindowPath") name_window = "Test.png" system.print.printToImage(window,name_window) fileName = "Test.png" fileData = fpmi.file.readFileAsBytes(fileName)"smtp.example","","Email de test","Contenu de l'email",0,[""],[fileName],[fileData])

Maybe this can be done using the system.dataset.dataSetToExcel function? But then I have to use file.writeFile to use the return of this function and specify a path, not just a name… Any idea?

1 Like

When using Windows VISTA/7/8, you can write to the public directory:


Yes, you should use the system.dataset.dataSetToExcel function.

You can use the system.file.getTempFile function to get a path to a temporary file that you write to.

Actually, you do not need to write the excel string to a file. All you need to do is convert the string into bytes and email the bytes.

Here is a code example:

table = event.source.parent.getComponent("Table")
excelstr = system.dataset.dataSetToExcel(True,[])
excelbytes = excelstr.encode("UTF8")
filename = "myexcelfile.xls""smtp.example","","Email de test","Contenu de l'email",0,[""],[filename],[excelbytes])
1 Like

Thanks a lot !! :prayer: