我想在通过电子邮件发送给特定的人之前,组合多个excel文档(通过从不同参数的SSRS报告导出获得)。每个文档都需要是“主人”中的新工作表。文档。
我有以下代码 - 除非EPPlus似乎将所有文本格式更改为具有粗体,斜体和透视样式;
DateTime startDate = DateTime.Today.AddDays(-7), endDate = DateTime.Today;
List<EnAccount> accounts = GetAccounts(startDate, endDate);
using (ExcelPackage excelPackage = new ExcelPackage())
{
foreach (EnAccount account in accounts)
using (MemoryStream reportStream = new MemoryStream(
GetReport("REPORTSERVERPATH", "REPORTPATH", "EXCELOPENXML", new List<ReportParameter>() { new ReportParameter("AccountID", account.AccountID.ToString()), new ReportParameter("StartDate", startDate.ToShortDateString()), new ReportParameter("EndDate", endDate.ToShortDateString()) })
))
using (ExcelPackage accountPackage = new ExcelPackage(reportStream))
excelPackage.Workbook.Worksheets.Add(account.AccountName, accountPackage.Workbook.Worksheets.First());
using (MemoryStream outputStream = new MemoryStream(excelPackage.GetAsByteArray()))
using (MailMessage message = new MailMessage())
{
message.To.Add(new MailAddress("email@email.com.au", "NAME"));
message.From = new MailAddress("email2@email.com.au", "TEST");
message.Subject = "SUBJECT";
message.Body = "BODY.";
message.Attachments.Add(new Attachment(outputStream, "Report.xlsx"));
SmtpClient smtpClient = new SmtpClient("MAILCLIENT");
smtpClient.Send(message);
}
}
任何人都可以帮助解决为什么它会更改此格式,以及如何让它保留原始格式? 提前感谢您的帮助。
答案 0 :(得分:0)