Sunday, October 7, 2012

Spreadsheetgear and dates

when you import dates from a s/sh , then if the format is set SG will get the value and format and allow you to acces the text. if however you are importing a csv - it will attempt to convert to the current culture

how to deal with a different format than the current culture:


CultureInfo TempCulture = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
                    TempCulture.DateTimeFormat.ShortDatePattern = dateFormat;
                    //Thread.CurrentThread.CurrentCulture = TempCulture;
                    _wb = SpreadsheetGear.Factory.GetWorkbookSet(TempCulture).Workbooks.OpenFromStream(stream);
                    _data = _wb.GetDataSet(SpreadsheetGear.Data.GetDataFlags.FormattedText );
 

when converting to datatables make sure to get the formatted text:



DataSet dataSet = wb.GetDataSet(SpreadsheetGear.Data.GetDataFlags.FormattedText );

likewise:

range.CopyFromDataTable(dt, SpreadsheetGear.Data.SetDataFlags.AllText);
 



No comments:

Post a Comment