How can I prevent the transmission of invisible columns

Hi

how can I prevent the transmission of invisible columns to excel or pdf ?

3 Replies

AK Adhikesevan Kothandaraman Syncfusion Team June 7, 2018 11:05 AM UTC

Hi Eren,  
 
Thanks for contacting Syncfusion support.  
 
The hidden columns of the SfDataGrid can be restricted while exporting by adding the column to the ExcludeColumns property of the ExcelExportingOptions and PdfExportingOptions.  
Please refer to the following code example and UG link for further reference,  
 
Excel Exporting  
ExcelExportingOptions GridExcelExportingOptions = new ExcelExportingOptions();  
List<string> hiddenColumns = new List<string>();  
foreach (var column in sfDataGrid1.Columns)  
{  
    if (!column.Visible)  
        hiddenColumns.Add(column.MappingName);  
}  
GridExcelExportingOptions.ExcludeColumns = hiddenColumns;  
  
var excelEngine = sfDataGrid1.ExportToExcel(sfDataGrid1.View, GridExcelExportingOptions);  
var workBook = excelEngine.Excel.Workbooks[0];  
workBook.SaveAs("Sample.xlsx");  
  
Pdf Exporting  
PdfExportingOptions pdfExportingOption = new PdfExportingOptions();  
List<string> hiddenColumns = new List<string>();  
foreach (var column in sfDataGrid.Columns)  
{  
    if (!column.Visible)  
        hiddenColumns.Add(column.MappingName);  
}  
  
pdfExportingOption.ExcludeColumns = hiddenColumns;  
  
var document = sfDataGrid.ExportToPdf(sfDataGrid.SelectedItems, pdfExportingOption);            document.Save("Sample.pdf");  
  
  
UG Link:  
 
Sample Link:   
  
Regards,  
Adhi  



ER Eren June 8, 2018 05:33 PM UTC

Thank you this help me a lot


AR Amal Raj U Syncfusion Team June 11, 2018 04:23 AM UTC

Hi Eren, 

Thanks for your update. 

We are glad to know, that the provided solution resolved your queries. Please let us know, if you need any further assistance on this. 

Regards, 
Amal Raj U. 


Loader.
Up arrow icon