Aspose.Cells.Examples.CSharp.Articles.FindQueryTablesAndListObjectsOfExternalDataConnections.PrintTables C# (CSharp) Méthode

PrintTables() public static méthode

public static PrintTables ( Workbook workbook, Aspose ec ) : void
workbook Workbook
ec Aspose
Résultat void
        public static void PrintTables(Workbook workbook, Aspose.Cells.ExternalConnections.ExternalConnection ec)
        {
            // Iterate all the worksheets
            for (int j = 0; j < workbook.Worksheets.Count; j++)
            {
                Worksheet worksheet = workbook.Worksheets[j];

                // Check all the query tables in a worksheet
                for (int k = 0; k < worksheet.QueryTables.Count; k++)
                {
                    Aspose.Cells.QueryTable qt = worksheet.QueryTables[k];

                    // Check if query table is related to this external connection
                    if (ec.Id == qt.ConnectionId
                        && qt.ConnectionId >= 0)
                    {
                        // Print the query table name and print its refersto range
                        Console.WriteLine("querytable " + qt.Name);
                        string n = qt.Name.Replace('+', '_').Replace('=', '_');
                        Name name = workbook.Worksheets.Names["'" + worksheet.Name + "'!" + n];
                        if (name != null)
                        {
                            Range range = name.GetRange();
                            if (range != null)
                            {
                                Console.WriteLine("refersto: " + range.RefersTo);
                            }
                        }
                    }
                }

                // Iterate all the list objects in this worksheet
                for (int k = 0; k < worksheet.ListObjects.Count; k++)
                {
                    ListObject table = worksheet.ListObjects[k];

                    // Check the data source type if it is query table
                    if (table.DataSourceType == Aspose.Cells.Tables.TableDataSourceType.QueryTable)
                    {
                        // Access the query table related to list object
                        QueryTable qt = table.QueryTable;

                        // Check if query table is related to this external connection
                        if (ec.Id == qt.ConnectionId
                        && qt.ConnectionId >= 0)
                        {
                            // Print the query table name and print its refersto range
                            Console.WriteLine("querytable " + qt.Name);
                            Console.WriteLine("Table " + table.DisplayName);
                            Console.WriteLine("refersto: " + worksheet.Name + "!" + CellsHelper.CellIndexToName(table.StartRow, table.StartColumn) + ":" + CellsHelper.CellIndexToName(table.EndRow, table.EndColumn));
                        }
                    }
                }
            }
        }
        // ExEnd:PrintTables
FindQueryTablesAndListObjectsOfExternalDataConnections