We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Date formatted column does not contain date filter options when filter applied

We have code that uses the .ImportDataTableFormat() method to create a workbook from datatables.

public Workbook BuildReport(DataSet reportData)
  var workBook = SetupWorkBook();
  workBook.Worksheets[0].Cells.ImportDataTable(reportData.Tables[0], true, "A1");
  workBook.Worksheets[1].Cells.ImportDataTable(reportData.Tables[1], false, "A1");

  //Set the style and format of col with index 1 to date
  Style style = workBook.CreateStyle();
  StyleFlag flag = new StyleFlag();
  style.Number = 14;
  flag.NumberFormat = true;
  Column col = workBook.Worksheets[0].Cells.Columns[1];
  col.ApplyStyle(style, flag);

  return workBook;

The line in bold seems to set the format of all cells correctly and achieves what we need. We only need this to be applied to specific columns in the workbook. The ConvertStringToNumericValue() method cannot be applied on a column, only all cells in the workbook.

Is there a way this can be applied to a column or cells in a column?


Thanks for the code segment and details.

Well, yes, Cells.ConvertStringToNumericValue method will convert all the so called strings to numeric data type (where appropriate). I think you may remove the bold line from your code and use the following code segment instead, it will work for your requirements:
Sample code:

//Get the last cell in the second column (B)
            Aspose.Cells.Cell endCell = workBook.Worksheets[0].Cells..EndCellInColumn(1);
            //Last row to loop through for B column
            int maxrow = endCell.Row;
            for (int i = 0; i <= maxrow; i++)

//Convert each value in the column to numeric/respective data type (if appropriate)
            workBook.Worksheets[0].Cells[i,1].PutValue(workBook.Worksheets[0].Cells[i,1].StringValue, true);

Hope, this helps a bit.