C# Excel Text to Column Problem -


hi i've called text column function in c# didn't turned out way wanted be.

i have data in first cell of worksheet.

guest;0;12/10/2010 03:46:34 pm;66082 

if run text column manually excel, get.

guest   0   12/10/2010 15:46    66082 

however if ran through c# code, get.

guest   0   10/12/2010 15:46    66082 

the date format have switched "dd/mm/yyyy" "mm/dd/yyyy"

here's c# code

((range)ws.cells[1,1]).entirecolumn.texttocolumns( type.missing, excel.xltextparsingtype.xldelimited,  excel.xltextqualifier.xltextqualifiernone, type.missing,  type.missing, true, type.missing,  type.missing, type.missing,  type.missing, type.missing,  type.missing, type.missing); 

i recorded macro excel.

selection.texttocolumns destination:=range("a1"), datatype:=xldelimited, _         textqualifier:=xlnone, consecutivedelimiter:=false, tab:=false, _         semicolon:=true, comma:=false, space:=false, other:=false, fieldinfo _         :=array(array(1, 1), array(2, 1), array(3, 1), array(4, 1)) 

the thing couldn't try out fieldinfo. had no idea how convert c#. not google either. i'm kinda suspecting xlgeneralformat.

any ideas? thanks.

object fieldinfo = new int[4,2] {{1,1},{2,1},{3,1},{4,1}}; 

ok realised problem not lies fieldinfo, runs fine if omit out.

the problem lies this.

wb.close(true, savefiledialog1.filename, type.missing); 

i saved file. , found original file in correct format wanted. newly saved file in wrong format.

i commented out close line, , saved manually. old file still in delimited form while new file still in wrong format.

apparently object filename works if it's "savefiledialog1.filename". in other words works if it's same file name. tried type.missing , @"c:\lalala.xls" , didn't text column.

i realise format in text column doesn't work -.- ok give up. i'm going convert datetime excel serial datetime. interesting problem nonetheless.

the book have (programming excel vba , .net, webb & saunders) describes fieldinfo "an array describes data types of fields in text". appear teh solution should there, macro not include date formatting.

the msdn ref docs more useful:

http://msdn.microsoft.com/en-us/library/04b02wh9%28v=vs.80%29.aspx

yes array: array of value pairs (hence array of array in macro). first value column number. second value xlcolumndatatype constant. definitions here:

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.xlcolumndatatype.aspx

note list of date formats. looks need xldmyformat or xlmdyformat value third column?

if know column(s) contain date (as above assumes), explicitly set format afterwards. saves faffing around arrays although turn 2 stage process.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -