c# - How to specify data types when dragging content to Excel -
i initiating drag , drop winforms application using simple
idataobject data = new dataobject(); string texttoexcel = "hello\tworld\t1\t2\nhello\tworld\t1\t2\n" data.setdata(dataformats.text, texttoexcel);
i works fine when dropped on excel, ends nicely in columns , rows. problem excel not know cells values 1 , 2 numerics , gets worse when dropping date value.
how can tell excel data types of individual cells, there richer type excel accepts when content being dropped it.
all able communicate drag-drop excel strings, excel automatically convert date or numeric type if can. if don't want convert identifable types data type should begin value appostrophe (') character, such '100, instead of 100.
if wish have full control, should subscribe excel.worksheet.change event triggered @ end of drag-drop action. @ point can custom conversion of own data. facilitated if transmit data custom format begin with, 1 not automatically converted excel. example, instead of sending 2x2 block of values such as:
100 hello $1.25 10/9/2010
you send through as:
<dragdrop:double>100</double> <dragdrop:string>hello</string> <dragdrop:currency>1.25</currency> <dragdrop:date>2010.10.9</date>
these values received cells strings. when worksheet.change event fires, tell cells have been changed, , routine process strings, looking begins "<dragdrop:"
. convert these required data types specified in strings themselves.
for detailed example, see article adding drag-and-drop functionality using .net framework , visual studio 2005 tools office second edition. in article, use example more unique "<dragdrop:"
-- use guid @ front of string make sure string unique , identifiable. basic strategy described, above.
hope helps,
mike
Comments
Post a Comment