Message-ID: <1915878238.2157.1710819563203.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_2156_1990947735.1710819563203" ------=_Part_2156_1990947735.1710819563203 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Modifying an Existing Spreadsheet

Modifying an Existing Spreadsheet

ExcelApplication can open and modify an existing spreadsheet. The n= ew spreadsheet can either be saved to disk (overwriting the original file o= r saved with a new name) or streamed to the browser. This allows you to use= a preset format for similar spreadsheets, rather than recreate the format = for each.

Alternatively, use an ExcelWriter tem= plate.

All features in the original workbook - including macros, charts, PivotT= ables, and VBA - will be preserved in the new workbook.

= How to Modify an Existing Spreadsheet

To modify an existing spreadsheet:

  1. Create an instance of ExcelApplication:

    =20
    ExcelApplication xla =3D new ExcelApplication();
    =20
  2. Open an Excel workbook from a file path or a System.IO.Stream:

    =20
    //--- Open a workbook from a file path:
    Workbook wb =3D xla.Open(@"C:\Reports\Report.xlsx");
    
    =20

    Or:

    =20
    //--- Open a workbook from a Stream:
    FileStream fs =3D new FileStream(@"C:\Sales\2003\June.xlsx", File=
    Mode.Open);
    Workbook wb =3D xla.Open(fs);
    
    =20
  3. Return a Worksheet object:

    =20
    Worksheet ws =3D wb.Worksheet[0];
    =20
  4. Modify the worksheet. For example, add a cell value:

    =20
    ws.Cells[0, 0].Value =3D "Welcome to SoftArtisans OfficeWri=
    ter";
    
    =20
  5. Save the modified file with a new name, or stream it to the client:<= /p>

    =20
    //--- Save the file on the server:
    xla.Save(wb, @"C:\temp\out.xlsx");
    
    =20

    Or:

    =20
    //--- 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);
    
    =20

    For more information on save options, see Output Options.

------=_Part_2156_1990947735.1710819563203--