我的程序允许我粘贴一个被复制并添加到列表视图的Excel。我想知道如何检查字符串是否真的是excel文件的副本。我找到了这个解决方案(c# : Excel : Determine if a string is a valid datasheet Range?),但它没有用。
from pyparsing import *
def pushFirst( strg, loc, toks ):
toks[0][2], toks[0][1] = toks[0][1], toks[0][2]
def parseTerm(term):
"""
EBNF syntax elements
EXCLAM = !
HAT = ^
STAR = *
SEMI = ;
LPAR = (
RPAR = )
"""
EXCLAM,HAT,STAR = map(Literal,"!^*")
LPAR,RPAR = map(Suppress,"()")
SEMI = Suppress(";")
token = oneOf(list(alphas.upper()))
expr = Forward()
expr <<= (
EXCLAM |
Group(Word(alphas.upper()) + SEMI + ungroup(expr)) |
Group(LPAR + expr + HAT + expr + RPAR).setParseAction( pushFirst ) |
Group(LPAR + expr + STAR + expr + RPAR).setParseAction( pushFirst )
)
try:
result = expr.parseString(term)
except ParseException as pe:
print ' '*pe.loc + '^'
print pe
return result[0]
def computeTerm(term):
print term
term = (parseTerm("(((AXX;!^B;!)^C;D;!)*E;!)"))
computeTerm(term)
上面链接中的解决方案表明了这个功能:
String cp = Clipboard.GetText();
string[] stringSeparators = new string[] { "\r\n" };
string[] rows = cp.Split(stringSeparators, StringSplitOptions.None);
for (int i = 0; i < rows.Length - 1; i++){
ListViewItem tempT = new ListViewItem(rows[i].Split('\t'));
listView.Items.Add(tempT);
}
错误说:
private bool IsRange(string refr) {
try {
Range(refr);
return true; // if no error occurred, refr is a valid range
}
catch {
return false; // not a valid range
}
}