|
楼主 |
发表于 2015-11-17 11:41
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
看过以下无需绑定数据源的方法:
ComboBox: Adding Text and Value to an Item (no Binding Source)
打算再测试以下代码:
- 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 = "";
- int n=0;
- Sh.DisplayMember = "Text";
- Sh.ValueMember = "Value";
- foreach (Worksheet s in book.Worksheets)
- {
- n++;
- //Sh.Items.Add(s.Name);
- Sh.Items.Add(new { Text = s.Name , Value = n.ToString();});
- //msg = msg + s.Name;
- }
- //System.Windows.Forms.MessageBox.Show(msg);
- //string[] array = { "软体学院", "经济管理学院", "外语学院", "公共管理学院", "体育学院", "化学学院", "计算技术学院", "人文科技学院", "法学学院", "文化传播学院", "物电科学技术学院" };
- //Sh.DataSource = array;
- }
- }
- }
复制代码 |
|