1

When I load an xls file, which is created by the user, to SpreadSheetGear workbook it changes date format from dd/mm/yyyy to mm/dd/yyyy. How can I prevent this?

I use the code below (VB.NET) to load xls file:

WorkbookView1.ActiveWorkbook =  
    SpreadsheetGear.Factory.GetWorkbookSet.Workbooks.OpenFromMemory(xlsFile)

xlsFile is a Byte array.

Donut
  • 110,061
  • 20
  • 134
  • 146
BoraTahir
  • 11
  • 1
  • 3

2 Answers2

4

I had the problem when importing excel xlsx to my site it was shifting the date from dd/MM/yyyy to MM/dd/yyyy though the system data was set to dd/MM/yyyy, the below method gave me the correct format I want.

 Dim dsFromExcel As DataSet = New DataSet
 Dim mywb As SpreadsheetGear.IWorkbook = SpreadsheetGear.Factory.GetWorkbook(strFileName)
 Dim myws As SpreadsheetGear.IWorksheet = mywb.Sheets(0)
 Dim Myrange As SpreadsheetGear.IRange = myws.Cells

'this will set the format of the first column A to this date format
 Myrange("A:A").NumberFormat = "MM/dd/yyyy HH:mm:ss"

'importing the data to a dataset/datatable
 dsFromExcel = mywb.GetDataSet(SpreadsheetGear.Data.GetDataFlags.FormattedText)

Dim dt As DataTable = New DataTable
dt = dsFromExcel.Tables(0)
Flexo
  • 87,323
  • 22
  • 191
  • 272
wissam
  • 41
  • 2
1

You should be able to open the workbook using a culture info that defaults to dd/mm/yyyy. This may be your current culture.

Dim myWorkBook As SpreadsheetGear.IWorkbook = SpreadsheetGear.Factory.GetWorkbook(fileName, new System.Globalization.CultureInfo('es-PR'))

This site gives a good overview of .Net Framework culture defaults. http://www.basicdatepicker.com/samples/cultureinfo.aspx

tmthydvnprt
  • 10,398
  • 8
  • 52
  • 72
mfreedm52
  • 161
  • 10