I want to combine multiple excel documents (obtained by exporting from an SSRS report with different parameters), before emailing to a particular person. Each document needs to be a new worksheet in a 'master' document.
I have the following code - which works, except EPPlus seems to change all text formatting to have bold, italic and strike-through styling;
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);
}
}
Can anyone help as to why it changes this formatting, and how i can get it to retain the original formatting? Thanks in advance for any help.
are you sure you need to do this? Create a "main" report in SSRS. In this report, add two lists with subreports inside. then on the lists properties, add a page break before. If you then run the main report, it will have a report on each sheet.
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.