Skip to content

Commit fa42f52

Browse files
authored
Merge pull request #2324 from syncfusion-content/999649-TableNameFAQ
Documentation(999649): Add How to get the external connection name from a QueryTable in an IListObject and how to change the table name FAQ
2 parents 919d46a + 913c0c3 commit fa42f52

2 files changed

Lines changed: 75 additions & 0 deletions

File tree

Document-Processing-toc.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6473,6 +6473,9 @@
64736473
<li>
64746474
<a href="/document-processing/excel/excel-library/net/faqs/how-to-get-the-file-extension-of-excel-file">How to get the file extension of an Excel file using XlsIO?</a>
64756475
</li>
6476+
<li>
6477+
<a href="/document-processing/excel/excel-library/net/faqs/how-to-get-external-connection-name-and-change-table-name">How to get the external connection name from a QueryTable in an IListObject and how to change the table name using XlsIO?</a>
6478+
</li>
64766479
</ul>
64776480
</li>
64786481
</ul>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: How to get external connection name and rename the table | 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 access the external connection name and rename the table name?
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

Comments
 (0)