简体   繁体   中英

How to remove filter from table in excel created by spreadsheet-light import data from a DataTable function.

I'm using Spreadsheet-light for creating excel document. I need to use a method "import data from a DataTable".But the table has filter by default. i do not want this filter.

在此输入图像描述

I tried a inbuilt method of Spreadsheet-light

sl.RemoveFilter();

to remove the filter but it's not working.Can any one suggest how to remove this default filter. Please look into my code.

int iStartRowIndex = 11;
int iStartColumnIndex = 2;
sl.ImportDataTable(iStartRowIndex, iStartColumnIndex, dtMyTable,true);
int iEndRowIndex = iStartRowIndex + dtMyTable.Rows.Count + 1 - 1;
int iEndColumnIndex = iStartColumnIndex + dtMyTable.Columns.Count - 1;
SLTable table = sl.CreateTable(iStartRowIndex, iStartColumnIndex, iEndRowIndex, iEndColumnIndex);
table.SetTableStyle(SLTableStyleTypeValues.Medium17);
sl.RemoveFilter();
sl.InsertTable(table);
sl.SaveAs("FileName");

This might come as a shock to you, but the solution is weirdly simple..

Just replace the statement

sl.RemoveFilter();

with this:

table.HasAutoFilter = false;

It took me some time to figure this out.. Some documentation is definitely needed for this!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM