Introduction
Developers can create new or manipulate existing Excel files on their websites in GUI mode using Aspose.Grid.Web control. Finally, developers can save their work to Excel files. So, Aspose.Grid.Web also serves as an Online Spreadsheet Editor. In this topic, we will describe that how developers can save their Grid content to Excel files.
Saving Excel Files
Saving as a File
To save the content of Aspose.Grid.Web control as an Excel file, follow the steps below:
- Add Aspose.Grid.Web control to your web form
- Save your work as an Excel file at a specified path
- Run your application
NOTE: If you don't know about how to add Aspose.Grid.Web control to your web form then you should refer to Creating Control on a Web Form
When Aspose.Grid.Web control is added to a windows form, the control is automatically instantiated and added to the form with a default size. So, you don't have to create an object of Aspose.Grid.Web control by yourself. All you have to do is to drag and drop the control and start using it.
The code snippet to save Grid content as an Excel file, is provided in the below example.
Example:
[C#]
//Saving Grid content to an Excel file
GridWeb1.WebWorksheets.SaveToExcelFile("D:\\book1.xls");
[VB.NET]
'Saving Grid content to an Excel file
GridWeb1.WebWorksheets.SaveToExcelFile("D:\\book1.xls")
NOTE: If your file system is NTFS, you should grant Read/Write access permissions to ASPNET or Everyone user accounts otherwise you will get an Access denied exception at runtime.
The above code snippet can be used by developers in any desired manner. A most common way could be to add a button that would save Grid content to an Excel file when clicked. But, Aspose.Grid.Web offers a more easier and reasonable approach to perform this task. Aspose.Grid.Web has an event named as SaveCommand as shown below in the figure:
|
Figure: SaveCommand event of the GridWeb
|
Developers can add above code snippet to the Event Handler of SaveCommand event, which would allow users to save their work to Excel files by clicking the built-in Save button of Aspose.Grid.Web as shown below in the figure:
|
Figure: Saving Grid content to Excel file by clicking built-in Save button of GridWeb
|
NOTE: If you are working in Visual Studio.NET then you can easily create the Event Handler of SaveCommand event by double clicking on the event in Properties pane. To learn more about this, please refer to Working with Aspose.Grid.Web Events.
Saving as a Stream
Sometimes, it might be required by developers to save their Grid content to a stream (For example, MemoryStream). To facilitate this task, Aspose.Grid.Web control also supports saving Grid data to a stream as shown below in the example.
Example:
[C#]
//Opening an Excel file as a stream
FileStream fs = File.OpenRead("d:\\book1.xls");
//Saving Grid content of the control to a stream
GridWeb1.WebWorksheets.SaveToExcelFile(fs);
//Closing stream
fs.Close();
[VB.NET]
'Opening an Excel file as a stream
Dim fs As FileStream = File.OpenRead("d:\\book1.xls")
'Saving Grid content of the control to a stream
GridWeb1.WebWorksheets.SaveToExcelFile(fs)
'Closing stream
fs.Close()
Describes how to create and use Aspose.Grid.Web control in a web application.
8/16/2006 5:38:12 AM - -210.56.19.13
Describes how to start working with Aspose.Grid.Web Events.
8/16/2006 6:14:39 AM - -210.56.19.13