This project has moved. For the latest updates, please go here.

Saving Updated copy of XLSX

Sep 28, 2013 at 3:53 PM
Edited Sep 28, 2013 at 4:03 PM
This works when creating a new XLSX:
      Dim XLSX_Out As New FileInfo("C:\XLSX_Out.xlsx")
      Using package As New ExcelPackage
           Dim worksheet As ExcelWorksheet = package.Workbook.Worksheets.Add("Test")
           worksheet.Cells("A1").Value = "AAAAAA"
           package.SaveAs(XLSX_Out)
      End Using

This Does not work when opening an XLSX, make a change and save it to a new file name:
      Dim XLSX_In As New FileInfo("C:\XLSX_In.xlsx")
      Dim XLSX_Out As New FileInfo("C:\XLSX_Out.xlsx")
      Using package As New ExcelPackage(XLSX_In)
            Dim worksheet As ExcelWorksheet = package.Workbook.Worksheets("Test")
            worksheet.Cells("A1").Value = "AAAAAA"
            package.SaveAs(XLSX_Out) 
      End Using
Last snippet Throws Error "Object reference not set to an instance of an object." on the SaveAs command. Can't figure out why. I converted this code from C# so I may have something wrong with my conversion.

I have also tried
       Using package As New ExcelPackage(XLSX_Out, XLSX_In)
       package.Save()
Same error.

Have also used Excel Template (XLTX) as input with same result.

Thanks!