Date Field Reading Issue from Excel file

Hi,

We are facing issue while reading date value from excel file.This issue is mostly occuring while handling with Armenian Type(Location).we are not getting currect value from this.Here i'm attaching sample file also.Could you please help to resolve his issue.

Thanks,

Deepu

Hello

Thanks for your inquiry. I will move your request to the Aspose.Cells forum and my colleagues will answer you shortly.

Best regards

Hi,

I have tested using your file on my system, it works as expected based on locality set for the windows.


Workbook workbook = new Workbook(“e:\test2\Sample.xls”);
Worksheet worksheet = workbook.Worksheets[0];
Aspose.Cells.Cell cell = worksheet.Cells[“A2”];
MessageBox.Show(cell.StringValue);// 31/03/2009 - OK
MessageBox.Show(cell.Value.ToString());// 3/31/2009 12:00:00 AM -OK
MessageBox.Show(cell.DateTimeValue.ToString());// 3/31/2009 12:00:00 AM -OK

What are your results?

I am using our latest version/fix v5.2.1.2(attached), we recommend you to try it.

Thank you.

Hi,

while assigning value to the string or message box it's showing the value.But while filling data table it's not accepting

PFA data file also

Could you please help

Could you please try this code?

Workbook workbook = new Workbook();

DataTable dtSectors = new DataTable();

dtSectors.Columns.Add("Date", typeof(DateTime));

dtSectors.Columns.Add("Employe Name", typeof(string));

dtSectors.Columns.Add("Employee Address", typeof(string));

workbook.Open("C:\\Documents and Settings\\user\\Desktop\\Sample.xls");

Worksheet worksheet = workbook.Worksheets[0];

Aspose.Cells.Cell cell = worksheet.Cells["A2"];

Aspose.Cells.Cell cell2 = worksheet.Cells["A3"];

worksheet.Cells.ExportDataTable(dtSectors, 1, 0, 6, false, false);

Thanks

Deepu

Hi Deepu,

The reason is simple, you have string values in A column e.g A2 - A6 instead of Date values.

For confirmation you may use:
Worksheet worksheet = workbook.Worksheets[0];
Aspose.Cells.Cell cell = worksheet.Cells[“A2”];
MessageBox.Show(cell.Type.ToString()); //IsString - OK

For your situation, you may define String column for your “Date” field. the following code works fine with your file.

Sample code:
Workbook workbook = new Workbook(“e:\test2\Samplev.xls”);
DataTable dtSectors = new DataTable();
dtSectors.Columns.Add(“Date”, typeof(string));
dtSectors.Columns.Add(“Employe Name”, typeof(string));
dtSectors.Columns.Add(“Employee Address”, typeof(string));

Worksheet worksheet = workbook.Worksheets[0];



worksheet.Cells.ExportDataTable(dtSectors, 1, 0, 6, false, false);

int i = workbook.Worksheets.Add();
workbook.Worksheets[i].Cells.ImportDataTable(dtSectors, false, 0, 0, dtSectors.Rows.Count, dtSectors.Columns.Count, false);
MessageBox.Show(dtSectors.Rows[0][0].ToString());

workbook.Save(“e:\test2\out.xls”);

Thank you.