We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to export only specific columns to Excel from DataTable VB.Net?

Thread ID:

Created:

Updated:

Platform:

Replies:

130848 Jun 7,2017 05:34 AM UTC Jun 12,2017 07:38 AM UTC Windows Forms 3
loading
Tags: XlsIO
Dhairya Joshi
Asked On June 7, 2017 05:34 AM UTC

Hello Experts,
I am working with default DataGridView, I load the data from datatable and exported same to Excel, but what if I want to export only selected columns to Excel for Ex. My DataTabke is having 20 Column, Now I want to give selection to User's hand that he/she can select the columns which they want to export I can do that by just loading the Titles in CheckListBox but after that How can I export only those columns which are selected?
 Solution I found by myself
>I can copy the selected columns to new DataTable and Export New DataTable : Which I feel not good option.

Is there any direct way of doing it?

2nd Question

I want to merge the cells to a specific number 
For Example : This is what we do to merge the Cells 

ws.Range("A1:AE1").Merge()
ws.Range("A1:AE1").Text = "Daily Report"

But as i asked in first question what if user is selecting 3 columns instead of 20 Columns.
Is ther any way I can merget the columns like ws.Range(1:30).Merge() ? Kind of option?


Thank You in Advance


Sridhar Sukumar [Syncfusion]
Replied On June 8, 2017 12:33 PM UTC

Hi Dhairya, 
 
Thank you for contacting Syncfusion support. 
 
Please find the details for the queries from below table. 
 
Query 
Response 
I am working with default DataGridView, I load the data from datatable and exported same to Excel, but what if I want to export only selected columns to Excel for Ex. My DataTabke is having 20 Column, Now I want to give selection to User's hand that he/she can select the columns which they want to export I can do that by just loading the Titles in CheckListBox but after that How can I export only those columns which are selected? 
 Solution I found by myself 
>I can copy the selected columns to new DataTable and Export New DataTable : Which I feel not good option. 
 
Is there any direct way of doing it? 
 
You can achieve your requirement by using TemplateMarkers in XlsIO. We have prepared a sample for this which can be downloaded from the following location. 
 
Sample link: 
 
To know more about TemplateMarkers, please refer the following UG documentation link for your reference. 
 
UG Documentation link: 
 
I want to merge the cells to a specific number  
For Example : This is what we do to merge the Cells  
 
ws.Range("A1:AE1").Merge() 
ws.Range("A1:AE1").Text = "Daily Report" 
 
But as i asked in first question what if user is selecting 3 columns instead of 20 Columns. 
Is ther any way I can merget the columns like ws.Range(1:30).Merge() ? Kind of option? 
 
You can specify row and column to get specific range from worksheet. For example, if you want to merge range from 1st column to 30th column then you can get range using following code example. 
 
Code snippet: 
int firstRow = 1; 
int firstColumn = 1; 
int lastRow = 1; 
int lastColumn = 30; 
 
worksheet.Range[firstRow, firstColumn, lastRow, lastColumn].Merge(); 

Kindly refer the below UG documentation to know more about accessing a cell or range in XlsIO.

UG Documentation link:
 
  
Regards, 
Sridhar. 


Dhairya Joshi
Replied On June 9, 2017 06:19 AM UTC

thanks you it worked ! 

Sridhar Sukumar [Syncfusion]
Replied On June 12, 2017 07:38 AM UTC

Hi Dhairya, 
 
Thank you for updating us.  
 
We are glad that your requirement is fulfilled. Please let us know if you need any further assistance. 
 
Regards, 
Sridhar. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;