Фильтруйте даты w.r.t и записывайте их в excel из datagrid.
Hi Team, I am trying to put a filter with input dates (From and To) before writing to excel as output. I tried the below logic but it is writing all the data as it is in Grid to Excel. I am unable to go ahead. Appreciates if someone can help me doing this? The Grid displays as below : Dates Name School Place 5/13/15 Shreyas ABC BLR 4/12/15 Amit XYZ MYS 6/24/15 Niraj MES BJP 11/10/15 Akshay NIT ENG 8/26/15 Natraj GVC BGK Expected : Examaple if the DateFrom : 5/13/15 and DateTo : 6/24/15.The output expected is : Dates Name School Place 5/13/15 Shreyas ABC BLR 6/24/15 Niraj MES BJP
Что я уже пробовал:
void WriteToExcel(DateTimePicker DateFrom,DateTimePicker DateTo) { ExcelWriter exlWtr = new ExcelWriter(); int rows = Grid.RowCount + 1; int cols = Grid.ColumnCount; if (rows == 0 || cols == 1) return; string[] colNames = new string[cols]; // Populate the Header names first int i = 0; for (int colItr = 0; colItr < cols; j++) { if (Grid.Columns[j].Visible) { colNames[i] = Grid.Columns[j].Name; i++; } } object[,] values = new object[rows, i]; //Copy the Column names for (int j = 0; j < i; j++) { values[0, j] = Grid.Columns[colNames[j]].HeaderText; } //Get the data now foreach (DataGridViewRow row in Grid.Rows) { for (int j = 0; j < i; j++) { //Grid[colNames[0], j].FormattedValue; // This displays the dates from the Grid //May be here i need to add the logic to filter with dates and write values[row.Index + 1, j] = Grid[colNames[j], row.Index].FormattedValue; } } exlWtr.createFile(false); exlWtr.writeRange(1, 1, 1, values); // Writes to Excel exlWtr.SetHorizontalAllignment(1, 1, Grid.Rows.Count + 1, i, "LEFT"); exlWtr.SetVisibility(true); }