This project has moved and is read-only. For the latest updates, please go here.

ExcelPackage.GetAsByteArray() throws exception

Jun 9, 2015 at 7:22 PM
Edited Jun 9, 2015 at 7:23 PM
My code is a follows:
using (Stream stream = File.OpenRead(@"C:\temp\myfile.xls"))
    using (Excel.ExcelPackage package = new Excel.ExcelPackage(stream))
    using (Excel.ExcelWorkbook wb = package.Workbook)
        for (int index = 1; index < wb.Worksheets.Count; index++)
            using (Excel.ExcelWorksheet ws = wb.Worksheets[index])
                Excel.ExcelPrinterSettings prs = ws.PrinterSettings;
                prs.Orientation = Excel.eOrientation.Landscape;
                prs.Scale = 83;
        byte[] data = package.GetAsByteArray();
I get a NullReferenceException on the last line there. I initially had a ExcelPackage.SaveAs() call, which did the same thing. package, of course, isn't null, if it were, it would have died in the third using.

I basically want to take an existing Excel file, set it for Landscape and scale it to 83%, so anything that accomplishes that will work for me.