Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

Description

Excerpt

If you pass Save an HttpResponse object, ExcelWriter will stream the generated file to the client. This method allows you to specify a default client-side file name, and whether the file should be opened in the browser window or in Microsoft Excel.

Signature
C#
C#
 public virtual void Save(System.Web.HttpResponse response, System.String attachmentName, boolean openInBrowser)
{signature}{signature:
}
Signature
vb.net
vb.net
Public Overridable Sub Save(ByVal response As System.Web.HttpResponse, ByVal attachmentName As String, ByVal openInBrowser As Boolean)
{signature}

{parameters}
{param:response}A {msdn:
Parameters
Param
response
response

A

Msdn
System.Http.Response

|

System.Http.Response

}

1System.Http.Response
object,

usually

{{

Page.Response

}}{param} {param:attachmentName}Specifies a name for the generated Excel file; this name will be displayed in the download dialog when the file is streamed to the browser.{param} {param:openInBrowser}If {{openInBrowser}} is set to {{true}}, and the user chooses to open the file, the file will open in the browser window. If {{openInBrowser}} is set to {{false}}, and the user chooses to open the file, the file will open in Microsoft Excel. By default, the file will open in the browser window. {note}not all browsers can embed an Excel file in the browser window{note}{param} {remarks} ExcelWriter allows you to save in both the Excel 97-03 BIFF8 format (.xls) or the new Office Open XML (.xlsx) format. The template file must be of the expected output format. Hence, if you wish to output .xls files, you must start with a .xls template, and if you wish to output .xlsx files, you must start with a .xlsx template. ExcelWriter does not support the creation or editing of .xlsx files with the [ExcelApplication] object.\ You can call {{Save}} more than once for a single instance of [ExcelTemplate]. This allows you to save more than one copy of a generated file, and/or both save the file on the server and stream it to the client.\ {remarks} {example} h6. Stream to the client and open in Excel When you pass an HttpResponse object to {{Save}}, ExcelWriter will stream the generated Excel file to the client. The browser will display a File Download dialog asking the user to open or save the file. The method's second parameter specifies a file name to display in the File Download dialog. If the method's third parameter \- [openInBrowser|#param-openInBrowser] \- is {{false}} and the user chooses to open the Excel file, the file will open in Microsoft Excel. {code:csharp|title=C#}

Param
attachmentName
attachmentName

Specifies a name for the generated Excel file; this name will be displayed in the download dialog when the file is streamed to the browser.

Param
openInBrowser
openInBrowser

If openInBrowser is set to true, and the user chooses to open the file, the file will open in the browser window. If openInBrowser is set to false, and the user chooses to open the file, the file will open in Microsoft Excel. By default, the file will open in the browser window.

Note

not all browsers can embed an Excel file in the browser window

Remarks

ExcelWriter allows you to save in both the Excel 97-03 BIFF8 format (.xls) or the new Office Open XML (.xlsx) format. The template file must be of the expected output format. Hence, if you wish to output .xls files, you must start with a .xls template, and if you wish to output .xlsx files, you must start with a .xlsx template. ExcelWriter does not support the creation or editing of .xlsx files with the ExcelApplication object.

You can call Save more than once for a single instance of ExcelTemplate. This allows you to save more than one copy of a generated file, and/or both save the file on the server and stream it to the client.

Example
Stream to the client and open in Excel

When you pass an HttpResponse object to Save, ExcelWriter will stream the generated Excel file to the client. The browser will display a File Download dialog asking the user to open or save the file. The method's second parameter specifies a file name to display in the File Download dialog. If the method's third parameter - openInBrowser - is false and the user chooses to open the Excel file, the file will open in Microsoft Excel.

Code Block
csharp
csharp
titleC#


            //--- Stream to the client
            //--- "Output.xls" will appear in the Save As dialog
            //--- The file will open in Excel
            xlTemplate.Save(Page.Response, "Output.xls", false);

            //--- Stream to the client
            //--- "Output.xlsx" will appear in the Save As dialog
            //--- The file will open in Excel 2007 only
            xlTemplate.Save(Page.Response, "Output.xlsx", false);
          
{code} {code:
Code Block
vb.net
|title=
vb.net
titlevb.net
}


            '--- Stream to the client
            '--- "Output.xls" will appear in the Save As dialog
            '--- The file will open in Excel
            xlTemplate.Save(Page.Response, "Output.xls", False)

            '--- Stream to the client
            '--- "Output.xlsx" will appear in the Save As dialog
            '--- The file will open in Excel 2007 only
            xlTemplate.Save(Page.Response, "Output.xlsx", False)
{code} h6. Stream to the client and open in the browser window When you pass an HttpResponse object to {{Save}}, ExcelWriter will stream the generated Excel file to the client. The browser will display a File Download dialog asking the user to open or save the file. The method's second parameter specifies a file name to display in the File Download dialog. If the method's third parameter \- [openInBrowser|#param-openInBrowser] \- is True and the user chooses to open the Excel file, the file will open in the browser window. {code:csharp|title=C#}
Stream to the client and open in the browser window

When you pass an HttpResponse object to Save, ExcelWriter will stream the generated Excel file to the client. The browser will display a File Download dialog asking the user to open or save the file. The method's second parameter specifies a file name to display in the File Download dialog. If the method's third parameter - openInBrowser - is True and the user chooses to open the Excel file, the file will open in the browser window.

Code Block
csharp
csharp
titleC#

            //--- Stream to the client
            //--- "Output.xls" will appear in the Save As dialog
            //--- The file will open in the browser's Excel plug-in
            xlTemplate.Save(Page.Response, "Output.xls", true);
            ...

            //--- Stream to the client
            //--- "Output.xlsx" will appear in the Save As dialog
            //--- The file will open in the browser's Excel 2007 plug-in
            xlTemplate.Save(Page.Response, "Output.xlsx", true);
{code} {code:
Code Block
vb.net
|title=
vb.net
titlevb.net
}

            '--- Stream to the client
            '--- "Output.xls" will appear in the Save As dialog
            '--- The file will open in the browser's Excel plug-in
            xlTemplate.Save(Page.Response, "Output.xls", True)
            ...

            '--- Stream to the client
            '--- "Output.xlsx" will appear in the Save As dialog
            '--- The file will open in the browser's Excel 2007 plug-in
            xlTemplate.Save(Page.Response, "Output.xlsx", True)
{code} {example}