|
楼主 |
发表于 2015-11-14 14:57
|
显示全部楼层
本打算是通过单击功能区按钮(Se)将指定的Excel文件全名赋给编辑框(Pa),而指定的Excel文件中的所有工作表是准备赋值给comboBox1的下拉选项的,可后一功能就是出错。盼指点......
代码:
- private void Se_Click(object sender, RibbonControlEventArgs e)
- {
- using (System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog())
- {
- openFileDialog.Filter = "Excel(*.xls;*.xlsx)|*.xls;**.xls*|All Files(*.*)|*.*";
- // 设置允许选择多个文件,该属性默认为false的,即只允许选择一个文件
- openFileDialog.Multiselect = true;
- if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- Pa.Text = openFileDialog.FileName;
- // 获得所有选定文件的文件名
- Shts = openFileDialog.FileNames;
- plmenu.Visible = true;
- mb1.Enabled = false;
- mb5.Enabled = false;
- Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
- Workbook book = app.Workbooks.Open(Pa.Text);
- comboBox1.Items.Clear();
- string msg = "";
- foreach (Worksheet s in book.Worksheets)
- {
- comboBox1.Items.Add(s.Name);
- msg = msg + s.Name;
- }
- System.Windows.Forms.MessageBox.Show(msg);
- string[] array = { "软体学院", "经济管理学院", "外语学院", "公共管理学院", "体育学院", "化学学院", "计算技术学院", "人文科技学院", "法学学院", "文化传播学院", "物电科学技术学院" };
- //Sh.DataSource = array;
- }
- }
- }
复制代码 |
|