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);
解决方案 »
- c#调用c的dll,报出:尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
- Regex.IsMatch这个静态方法只能判断是否包含,有没有类似像indexof()那样可以获得所在位置的正则或其他高级算法呢?
- GPRS数据流传输问题
- C#winform中Textbox.text中让输入的信息只能是数字不能是符号或字母
- 有人研究过qq msn 飞信这些聊天工具吗?
- 各位GGJJDDMM门,线程同步问题
- 关于处理用户请求的问题!(asp.net C#)
- 求助,c#文件中写入中文时自动产生bom
- c# winform 如何保护数据库连接字符串
- C#的数组不是说是动态的吗?我如何重新数组定义大小呢?
- sql server 的安装使用
- 请问窗体的“隐藏”和“关闭”有什么区别?
然后 TextBox[0] 就是对应 "this.textAA",如些类推,这时就可以用数组操作了。
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];
照此类推。
this.textName.Text = getValue(mysheet, 1, 2); ==> this.textName.Text = sheet[0][1];
就是每次要賦值如何,就要調用一次getValue(mysheet, i + 1, j + 1)方法,可以只用一次這個就能把所有的值都拿到嗎?不用反復使用同一方法
{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]);
}