Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

  1. Create an instance of ExcelApplication:
    Code Block
    c#
    c#
    ExcelApplication xla = new ExcelApplication();
  2. Open an Excel workbook from a file path or a System.IO.Stream:
    Code Block
    c#
    c#
    //--- Open a workbook from a file path:
    Workbook wb = xla.Open(@"C:\Reports\Report.xlsx");
    
    Or:
    Code Block
    c#
    c#
    //--- Open a workbook from a Stream:
    FileStream fs = new FileStream(@"C:\Sales\2003\June.xlsx", FileMode.Open);
    Workbook wb = xla.Open(fs);
    
  3. Return a Worksheet object:
    Code Block
    c#
    c#
    Worksheet ws = wb.Worksheet[0];
  4. Modify the worksheet. For example, add a cell value:
    Code Block
    c#
    c#
    ws.Cells[0, 0].Value = "Welcome to SoftArtisans OfficeWriter";
    
  5. Save the modified file with a new name, or stream it to the client:
    Code Block
    c#
    c#
    //--- Save the file on the server:
    xla.Save(wb, @"C:\temp\out.xlsx");
    
    Or:
    Code Block
    c#
    c#
    //--- Stream the file to the client via HTTP:
    //--- false means Open In Excel, true means Open In Browser (IE only)
    xla.Save(wb, Page.Response, "out.xlsx", false);
    
    For more information on save options, see Output Options.
    \