取得Excel中的实际数据,去除列和行的大片空白 public static List<string> SceneRainAndTemp(ref Array ary) { int oldrows =ary.GetLength(0); int oldcols = ary.GetLength(1); string sc= ""; string sr= ""; //List<string>存储二维数组,将一行作为一个字符串 List<string> dealedDatas = new List<string >(); for (int k = 1; k < oldcols; k++) { sc+= ary.GetValue(1, k).ToString() + "/t"; } dealedDatas.Add(sc); string s2 = sc.Trim(); string[] s3 = s2.Split('/t'); int colslen = s3.Length; //计算出实际的列长度 for (int x = 1; x < oldrows; x++) { sr+= ary.GetValue(x, 1).ToString() + "/t"; } string s4 = sr.Trim(); string[] s5 = s4.Split('/t'); int rowslen = s5.Length; //计算出实际的行长度 for (int i = 2; i <= rowslen+1; i++) { string temp = ""; for (int j = 1; j <= colslen; j++) { // if (ary.GetValue(i, j).ToString() != "") //Excel中(1,1)为空,没有这个判断,后面的字符串中会多出单独的/t,并且Excel中许多空元素 //{ temp += ary.GetValue(i, j).ToString() + "/t";//Array取得元素GetValue(i, j),不能用[i][j],Array中存储的是Object,要转化为string类型 //} } dealedDatas.Add(temp); } return dealedDatas;