Bir 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.

  1. Dosya Olarak Kaydetme
  2. Akış Olarak Kaydetme

Dosya kaydediliyor

Bir masaüstü uygulaması oluşturun ve GridControl denetimiyle forma iki düğme ekleyin. Düğmelerin metin özelliklerini şu şekilde ayarlayın:Dosya Olarak Kaydet veAkış Olarak Kaydet sırasıyla.

Dosya Olarak Kaydetme

Tıklama olayını oluşturunDosya Olarak Kaydet butonuna basın 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);
// 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ış Olarak Kaydetme

Bazen, geliştiricilerin Grid içeriklerini bir akışa kaydetmeleri gerekebilir (Örneğin, MemoryStream). Bu görevi kolaylaştırmak için Aspose.Cells.GridDesktop kontrolü, Grid verilerinin bir akışa kaydedilmesini de destekler. Tıklama olayını oluşturunAkış Olarak Kaydet butonuna basın 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();