Saturday, October 31, 2009

键盘上的符号发音

~
tilde (sounds like til-da); be prepared to explain to computer-illiterate people saying "you know, the wave-shaped thingy"

!
exclamation; commonly read as bang in case of #!/bin/sh

@
at

#
pound; but commonly read as shee in case of #!/bin/sh, not sure why

$
dollar

%
percent

^
caret; not many people know this word so be prepared to say "no, not carrot; it's the character above 6, an arrow pointing up"

&
ampersand

*
star; some read asterisk

(
opening parenthesis (some may shorten it saying paren)

)
closing parenthesis

_
underscore; once I heard people say underbar

+
plus

-
minus; as symbol before arguments in commands, some people including me read dash, easier to say one syllable

=
equals

`
backtick or backquote

{
opening brace

}
closing brace

[
opening bracket

]
closing bracket

|
pipe or vertical bar

\
backslash; be prepared to explain to some computer-illiterate people

:
colon

;
semicolon

"
double quote

'
single quote

<
less than; some may read left angle bracket

>
greater than

,
comma

.
dot; period if in English text

?
question mark

/
slash or forward slash; some computer-illiterate people may be confused about / and \

space

(), [] and {}
may also be called brackets in general. In that case, they specifically call [] square brackets and {} curly brackets. I never like this. Open and Closing may also be called left and right.

Thursday, October 8, 2009

c# copy excel data and paste into datagridview table

This post is about managing the memory data object after ctrl+c is used in Excel. You will learn how data are organised in memory and should be able to apply it anywhere. The code example tries to read the data in DataObject out and paste it in datagridview.            


DataObject o = (DataObject) Clipboard.GetDataObject(); 
if (o.GetDataPresent(DataFormats.Text))
{
int rowOfInterest = DataGridView.CurrentCell.RowIndex;
string[] selectedRows = Regex.Split(o.GetData(DataFormats.Text).ToString( ).TrimEnd( "\r\n".ToCharArray() ), "\r\n");

if (selectedRows == null || selectedRows.Length == 0)
return;

foreach (string row in selectedRows)
{
if (rowOfInterest >= DataGridView.Rows.Count)
break;

try
{
string[] data = Regex.Split(row, "\t");
int col = DataGridView.CurrentCell.ColumnIndex;

foreach (string ob in data)
{
if (col >= DataGridView.Columns.Count)
break;
if (ob!=null)
DataGridView[col, rowOfInterest].Value = Convert.ChangeType( ob, DataGridView[col,rowOfInterest].ValueType );
col++;
}
}
catch (Exception enterException)
{
//do something here
}
rowOfInterest++;
}
}