0

次のコードを使用しています。

var assembly =          Assembly.GetExecutingAssembly();
        Stream streamToTemplete=assembly.GetManifestResourceStream("DailyAuction.xltx");
        Stream streamToOutput = assembly.GetManifestResourceStream("dailyAuctionEmail.xls");


        //using (ExcelPackage excelPackage = new ExcelPackage(newFile, templateFile))

        using(streamToTemplete)
        using (streamToOutput)
        {

            using (ExcelPackage excelPackage = new ExcelPackage(streamToOutput, streamToTemplete))
            {

                ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets["Daily Auction"];
                int startRow = 4;
                int row = startRow;
                foreach (DailyEmail dailyEmail in listDailyEmail)                                                                                                                           //iterate through all the rows in the list
                {
                    worksheet.Cells[row, 1].Value = dailyEmail.As_At.ToString("dd-MMM-yy HH:mm");
                    worksheet.Cells[row, 2].Value = dailyEmail.Auction_Date.ToString("dd-MMM-yy");

                }
                excelPackage.Save();
            }
        }

        var attachment = new Attachment(streamToOutput, new ContentType("application/vnd.ms-excel"));

ただし、streamToTemplate と streamToOutput が null であるというエラーが表示されます。問題に見えるのは?また、残りのコードは機能しますか?

4

1 に答える 1