Çalışsaydı, Çalışma Sorgusu Tablosu Okuma ve Yazma
Aspose.Cells, İçerikSorgusunu döndüren Worksheet.QueryTables koleksiyonunu sağlar. Bu koleksiyon bir endekse göre QueryTable türünde bir nesne döndürür. Aşağıdaki iki özelliğe sahiptir
- QueryTable.AdjustColumnWidth
- QueryTable.PreserveFormatting
Bunlar her ikisi de Boolean değerlerdir. Bunları Microsoft Excel’de Veri > Bağlantılar > Özellikler menüsünde görebilirsiniz.
Çalışsayfa Sorgu Tablosu Okuma ve Yazma
Aşağıdaki örnek kod, ilk çalışsayfanın ilk Sorgu Tablosunu okur ve ardından Sorgu Tablosunun her iki özelliğini de yazdırır. Daha sonra QueryTable.PreserveFormatting özelliğini true olarak ayarlar.
Bu kodda kullanılan kaynak Excel dosyasını ve kod tarafından oluşturulan çıktı Excel dosyasını aşağıdaki bağlantılardan indirebilirsiniz.
// 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 = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook from source excel file | |
Workbook workbook = new Workbook(dataDir + "Sample.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access first Query Table | |
QueryTable qt = worksheet.QueryTables[0]; | |
// Print Query Table Data | |
Console.WriteLine("Adjust Column Width: " + qt.AdjustColumnWidth); | |
Console.WriteLine("Preserve Formatting: " + qt.PreserveFormatting); | |
// Now set Preserve Formatting to true | |
qt.PreserveFormatting = true; | |
// Save the workbook | |
workbook.Save(dataDir + "Output_out.xlsx"); |
Konsol Çıktısı
Yukarıdaki örnek kodun konsol çıktısı aşağıdaki gibidir
Adjust Column Width: True
Preserve Formatting: False
Sorgu tablosu sonuç aralığını alın
Aspose.Cells, bir sorgu tablosu için hücrelerin adresini yani sonuç aralığını okuma seçeneği sağlar. Aşağıdaki kod, bir sorgu tablosunun sonuç aralığının adresini okuyarak bu özelliği göstermektedir. Örnek dosyayı buradan indirebilirsiniz.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Create workbook from source excel file | |
Workbook wb = new Workbook("Query TXT.xlsx"); | |
// Display the address(range) of result range of query table | |
Console.WriteLine(wb.Worksheets[0].QueryTables[0].ResultRange.Address); |