我已经创建了一个带有组合框的WPF,我想从excel文件中显示一个列表 [英] I have created a WPF with a combobox on it I want to show a list from a excel file

查看:65
本文介绍了我已经创建了一个带有组合框的WPF,我想从excel文件中显示一个列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中,我使用System.Windows.Controls将代码编写为

In My code behind i have written code as

using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplicationList
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            string[] file =  File.ReadAllLines(@"C:\Users\vijay.singh\DATA\ABC.xlsx");
        

            for (int i=0;i<file.Length;i++)
            {
                comboBox1.Items.Add(file[i]);

            }
                    
        }
    }
}





我尝试了什么:



我试过调试它但是它在combobox中显示内容为corrupt.it没有显示为字符串。



What I have tried:

I have tried debugging it but it shows content in combobox as corrupt.it is not shown as string.

推荐答案

您无法以这种方式阅读Excel文件,其内容不会存储为简单的文本行。您需要使用OLEDB:使用MS Excel (xls / xlsx)使用MDAC和Oledb [ ^ ],或Excel Interop: Microsoft.Office.Interop.Excel namespace() [ ^ ]。
You cannot read Excel files in that way, their content is not stored as simple lines of text. You need to use OLEDB: Working with MS Excel(xls / xlsx) Using MDAC and Oledb[^], or the Excel Interop: Microsoft.Office.Interop.Excel namespace ()[^].


这篇关于我已经创建了一个带有组合框的WPF,我想从excel文件中显示一个列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆