Excel Dosyasını Kaydetme
Giriş
Aspose.Cells.GridDesktop kontrolünün içeriğini bir Excel dosyası olarak kaydetmek için, Aspose.Cells.GridDesktop aşağıdaki yöntemleri sağlar.
- Dosya Olarak Kaydetme
- Akışa Kaydetme
Dosya Kaydetme
Bir masaüstü uygulaması oluşturun ve formunuza bir GridControl kontrolü ile iki düğme ekleyin. İlgili düğmelerin metin özelliklerini sırasıyla Dosya Olarak Kaydet ve Akışa Kaydet olarak ayarlayın.
Dosya Olarak Kaydetme
Dosya Olarak Kaydet düğmesinin Click olayını oluşturun ve aşağıdaki kodu yapıştırın.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Saving Grid contents to an Excel file | |
gridDesktop1.ExportExcelFile(dataDir + "book1_out.xls"); | |
// Saving Grid contents to MS Excel 2007 Xlsx file format | |
gridDesktop1.ExportExcelFile(Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType) + "book1_out.xlsx", FileFormatType.Excel2007Xlsx); |
Akışa Kaydetme
Geliştiricilerin bazen Grid içeriğini bir akışa (örneğin, MemoryStream) kaydetmesi gerekebilir. Bu görevi kolaylaştırmak için, Aspose.Cells.GridDesktop kontrolü ayrıca Grid verilerini bir akışa kaydetmeyi destekler. Stream Olarak Kaydet düğmesinin Click olayını oluşturun ve içine aşağıdaki kodu yapıştırın.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Opening an Excel file as a stream | |
FileStream fs = File.Open(dataDir + "book1_out.xls", FileMode.Open, FileAccess.ReadWrite); | |
// Saving Grid contents of the control to a stream | |
gridDesktop1.ExportExcelFile(fs); | |
// Closing stream | |
fs.Close(); |