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

Simple Help

Jul 24, 2011 at 1:14 AM

Hi... I just tried to create a simple worksheet in a windows app in C#, VS2010... I step through the debugger and nothing throws an error BUT the spreadsheet doesn't get written.   Without posting the code, is there something obvious that I may be missing?   I used the EPPlusSample.Sample1.cs as a guide.

Thanks,

Steve

Editor
Jul 24, 2011 at 1:16 AM

Maybe you forgot to call Save method ?

Jul 24, 2011 at 1:40 AM

I got that ... when I don't create a worksheet I do get an error saying there must be at least 1 worksheet so I think that the Save() is working.   I've stripped the code down to almost nothing:

Here is the calling code

          RenewalWorksheet o = new RenewalWorksheet();
          o.Generate();

And here is the class:

  public class RenewalWorksheet
  {
    protected FileInfo xlsFile;

    public RenewalWorksheet() { }

    public void CreateFile()
    {
      FileInfo xlsFile = new FileInfo(@"C:\temp\AAAA.xlsx");
      if (xlsFile.Exists)
      {
        xlsFile.Delete();  // ensures we create a new workbook
        xlsFile = new FileInfo(@"C:\temp\AAAA.xlsx");
      }
    }
    protected void CreateSummaryPage(ExcelPackage e)
    {
      ExcelWorksheet work = e.Workbook.Worksheets.Add("Summary");

      work.Cells[1,1].Value = "region";
      work.Cells[1,2].Value = "applicationstatus";
      work.Cells[1,3].Value = "Tot_Leagues";
    }

    public void Generate()
    {
      this.CreateFile();
      try
      {
        using (ExcelPackage package = new ExcelPackage(this.xlsFile))
        {
          this.CreateSummaryPage(package);

          package.Save();
        }
      }
      catch (Exception e)
      {
        InfoBox.Show(e.Message);
      }
    }

Jul 24, 2011 at 1:55 AM

Never mind... stupid me... brain fart... had local instance of the file not going to the property... it's working now... thanks...