Excel.ApplicationClass my = new Excel.ApplicationClass();
                object missing = Missing.Value;
                string filename = @"C:\副本出货标签格式.xls";
                Excel.Workbook mybook = my.Workbooks.Open(filename, missing, missing, missing, missing,
                    missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);                Excel.Worksheet mysheet = (Excel.Worksheet)mybook.Worksheets.get_Item(1);
                this.textName.Text = getValue(mysheet, 1, 2);
                this.textBin.Text = getValue(mysheet, 2, 2);
                this.textTotalQTY.Text = getValue(mysheet, 3, 2);
                this.textDate.Text = getValue(mysheet, 4, 2);
                this.textTime.Text = getValue(mysheet, 5, 2);
                this.textMCNo.Text = getValue(mysheet, 6, 2);
                this.textLotNo.Text = getValue(mysheet, 7, 2);
                this.textBINTable.Text = getValue(mysheet, 8, 2);
                this.textBINName.Text = getValue(mysheet, 9, 2);
                this.textWaferName.Text = getValue(mysheet, 10, 2);
                this.textBarcodeNo.Text = getValue(mysheet, 11, 2);
                this.textAA.Text = getValue(mysheet, 14, 2);
                this.textAB.Text = getValue(mysheet, 14, 3);
                this.textAC.Text = getValue(mysheet, 14, 4);
                this.textAD.Text = getValue(mysheet, 14, 5);
                this.textBA.Text = getValue(mysheet, 15, 2);
                this.textBB.Text = getValue(mysheet, 15, 3);
                this.textBC.Text = getValue(mysheet, 15, 4);
                this.textBD.Text = getValue(mysheet, 15, 5);
                this.textCA.Text = getValue(mysheet, 16, 2);
                this.textCB.Text = getValue(mysheet, 16, 3);
                this.textCC.Text = getValue(mysheet, 16, 4);
                this.textCD.Text = getValue(mysheet, 16, 5);
                this.textDA.Text = getValue(mysheet, 17, 2);
                this.textDB.Text = getValue(mysheet, 17, 3);
                this.textDC.Text = getValue(mysheet, 17, 4);
                this.textDD.Text = getValue(mysheet, 17, 5);
                this.txtType.Text = getValue(mysheet, 8, 2);
                mysheet.ClearCircles();
                mybook.Close(filename, missing, missing);

解决方案 »

  1.   

    先定义一个 TextBox 类型的数组,并把所用到的TextBox控件加进去,如 TextBox[] textBoxArray = new TextBox[] {this.textAA,this.textAB...}
    然后 TextBox[0] 就是对应 "this.textAA",如些类推,这时就可以用数组操作了。
      

  2.   

    我不是要textbox的array我是要后面的getValue(mysheet, 14, 2)用Array完成!
      

  3.   


                string[][] sheet = new string[17][];            for (int i = 0; i < 17; i++)
                {
                    sheet[i] = new string[5];                for (int j = 0; j < 5; j++)
                        sheet[i][j] = getValue(mysheet, i + 1, j + 1);
                }取值的时候:
    this.textName.Text = getValue(mysheet, 1, 2);  ==>  this.textName.Text = sheet[0][1];
    this.textBin.Text = getValue(mysheet, 2, 2);  ==>  this.textBin.Text = sheet[1][1];
    照此类推。
      

  4.   

    不好意思  估計解釋的不清楚,就是
    this.textName.Text = getValue(mysheet, 1, 2); ==> this.textName.Text = sheet[0][1];
    就是每次要賦值如何,就要調用一次getValue(mysheet, i + 1, j + 1)方法,可以只用一次這個就能把所有的值都拿到嗎?不用反復使用同一方法
      

  5.   

    object[,] mapping = { 
    {textName, 1, 2},
    {textBin, 2, 2},
    {textTotalQTY, 3, 2},
    {textDate, 4, 2},
    {textTime, 5, 2},
    {textMCNo, 6, 2},
    {textLotNo, 7, 2},
    {textBINTable, 8, 2},
    {textBINName, 9, 2},
    {textWaferName, 10, 2},
    {textBarcodeNo, 11, 2},
    {textAA, 14, 2},
    {textAB, 14, 3},
    {textAC, 14, 4},
    {textAD, 14, 5},
    {textBA, 15, 2},
    {textBB, 15, 3},
    {textBC, 15, 4},
    {textBD, 15, 5},
    {textCA, 16, 2},
    {textCB, 16, 3},
    {textCC, 16, 4},
    {textCD, 16, 5},
    {textDA, 17, 2},
    {textDB, 17, 3},
    {textDC, 17, 4},
    {textDD, 17, 5},
    {txtType, 8, 2}
    };
    for (int i = 0; i < mapping.GetLength(0); i++)
    {
    (mapping[i, 0] as TextBox).Text = getValue(mysheet, (int)mapping[i, 1], (int)mapping[i, 2]);
    }