|
| 1 | +--- |
| 2 | +title: How to access external connection name and change table name | Syncfusion |
| 3 | +description: This page shows how to access a QueryTable's external connection name and how to change a table name using Syncfusion .NET Excel library (XlsIO). |
| 4 | +platform: document-processing |
| 5 | +control: XlsIO |
| 6 | +documentation: UG |
| 7 | +--- |
| 8 | + |
| 9 | +# How to get the external connection name from a QueryTable in an IListObject and how to change the table name using XlsIO? |
| 10 | + |
| 11 | +The example below shows how to read the external connection name from a [QueryTable](https://help.syncfusion.com/cr/document-processing/Syncfusion.XlsIO.Implementation.QueryTableImpl.html#Syncfusion_XlsIO_Implementation_QueryTableImpl_ExternalConnection) on a [ListObject](https://help.syncfusion.com/cr/document-processing/Syncfusion.XlsIO.IListObjects.html) (table) and how to rename the table using Syncfusion XlsIO. Ensure the worksheet contains a ListObject with an associated QueryTable. |
| 12 | + |
| 13 | +{% tabs %} |
| 14 | +{% highlight c# tabtitle="C# [Cross-platform]" %} |
| 15 | +using (ExcelEngine excelEngine = new ExcelEngine()) |
| 16 | +{ |
| 17 | + IApplication application = excelEngine.Excel; |
| 18 | + application.DefaultVersion = ExcelVersion.Xlsx; |
| 19 | + IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx"); |
| 20 | + IWorksheet worksheet = workbook.Worksheets[0]; |
| 21 | + IListObject table = worksheet.ListObjects[0]; |
| 22 | + |
| 23 | + // Get connection name |
| 24 | + string connectionName = table.QueryTable.ExternalConnection.Name; |
| 25 | + |
| 26 | + // Change table name |
| 27 | + table.Name = "New table name"; |
| 28 | + |
| 29 | + // Saving the workbook |
| 30 | + workbook.SaveAs("Output.xlsx"); |
| 31 | +} |
| 32 | +{% endhighlight %} |
| 33 | + |
| 34 | +{% highlight c# tabtitle="C# [Windows-specific]" %} |
| 35 | +using (ExcelEngine excelEngine = new ExcelEngine()) |
| 36 | +{ |
| 37 | + IApplication application = excelEngine.Excel; |
| 38 | + application.DefaultVersion = ExcelVersion.Xlsx; |
| 39 | + IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx"); |
| 40 | + IWorksheet worksheet = workbook.Worksheets[0]; |
| 41 | + IListObject table = worksheet.ListObjects[0]; |
| 42 | + |
| 43 | + // Get connection name |
| 44 | + string connectionName = table.QueryTable.ExternalConnection.Name; |
| 45 | + |
| 46 | + // Change table name |
| 47 | + table.Name = "New table name"; |
| 48 | + |
| 49 | + // Saving the workbook |
| 50 | + workbook.SaveAs("Output.xlsx"); |
| 51 | +} |
| 52 | +{% endhighlight %} |
| 53 | + |
| 54 | +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} |
| 55 | +Using excelEngine As New ExcelEngine() |
| 56 | + Dim application As IApplication = excelEngine.Excel |
| 57 | + application.DefaultVersion = ExcelVersion.Xlsx |
| 58 | + Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.xlsx") |
| 59 | + Dim worksheet As IWorksheet = workbook.Worksheets(0) |
| 60 | + Dim table As IListObject = worksheet.ListObjects(0) |
| 61 | + |
| 62 | + ' Get connection name |
| 63 | + Dim connectionName As String = table.QueryTable.ExternalConnection.Name |
| 64 | + |
| 65 | + ' Change table name |
| 66 | + table.Name = "New table name" |
| 67 | + |
| 68 | + ' Saving the workbook |
| 69 | + workbook.SaveAs("Output.xlsx") |
| 70 | +End Using |
| 71 | +{% endhighlight %} |
| 72 | +{% endtabs %} |
0 commit comments