DBConnection.PowerQueryFormula
DBConnection.PowerQueryFormula property
Gets the definition of power query formula.
public override PowerQueryFormula PowerQueryFormula { get; }
Examples
namespace AsposeCellsExamples
{
using Aspose.Cells;
using Aspose.Cells.ExternalConnections;
using Aspose.Cells.QueryTables;
using System;
public class DBConnectionPropertyPowerQueryFormulaDemo
{
public static void Run()
{
// Create a new workbook
Workbook workbook = new Workbook();
try
{
// Access the collection of external connections
ExternalConnectionCollection connections = workbook.DataConnections;
// Find the first DBConnection in the collection (if any)
DBConnection dbConn = null;
foreach (ExternalConnection conn in connections)
{
if (conn is DBConnection dbConnection)
{
dbConn = dbConnection;
break;
}
}
if (dbConn == null)
{
Console.WriteLine("No DBConnection objects found in the workbook.");
}
else
{
// Access the PowerQueryFormula property (read-only)
PowerQueryFormula powerQueryFormula = dbConn.PowerQueryFormula;
if (powerQueryFormula != null)
{
// Display the properties of PowerQueryFormula
Console.WriteLine("PowerQueryFormula Type: " + powerQueryFormula.Type);
Console.WriteLine("PowerQueryFormula GroupName: " + powerQueryFormula.GroupName);
Console.WriteLine("PowerQueryFormula FormulaDefinition: " + powerQueryFormula.FormulaDefinition);
Console.WriteLine("PowerQueryFormula Name: " + powerQueryFormula.Name);
Console.WriteLine("PowerQueryFormula Description: " + powerQueryFormula.Description);
// Demonstrate accessing the PowerQueryFormulaItems collection
Console.WriteLine("Number of PowerQueryFormulaItems: " + powerQueryFormula.PowerQueryFormulaItems.Count);
}
else
{
Console.WriteLine("PowerQueryFormula is null for this connection.");
}
}
// Save the workbook
workbook.Save("PowerQueryFormulaDemo.xlsx");
Console.WriteLine("Workbook saved as PowerQueryFormulaDemo.xlsx");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
}
See Also
- class PowerQueryFormula
- class DBConnection
- namespace Aspose.Cells.ExternalConnections
- assembly Aspose.Cells