简体   繁体   中英

C#: copy range of cells from excel sheet and paste in HTML email body

I have an Excel sheet. The data is pretty straight forward in a few columns and rows. There is some formatting done on the cells (example.. colors, bold font, etc). I am using c# to send email. I wish to basically copy the contents of the Excel sheet and paste it in the body of the email with the formatting maintained.

Is this even possible? Am I talking BS?

That's not an easy one. I mean you would have to check the style of every character in every cell! Wouldn't it be easier to just send the excel sheet? If you provide more information about WHY you are doing it like this we might be able to suggest some alternatives which won't be so time consuming!

Edit:

The easiest is to use the Workbook.SendMail() method.

The Code:

Excel.Workbook myWorkbook = xlApp.Workbooks["Book1.xls"];`
string recipients = "ElvisPresley@gmail.com";
string subject = "No need to open the attachment, you lazy ****";
bool returnReceipt = false;    
myWorkbook.SendMail(recipients, subject, returnReceipt);

Note that the recipients parameter is actually typed as System.Object so that the argument passed in can be a string[] if you have multiple recipients.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM