• 大小: 0.04M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-04-28
  • 语言: C#
  • 标签: TreeView  Excel  view  tree  表格  

资源简介


资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace treeview
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        string xlsname = ““;
        DataSet ds = new DataSet();
        DataTable alldata = null;
        OleDbConnection conn = null;
        private void readxls(string args_xlsname)
        {

            string connstr = “Provider=Microsoft.ACE.OLEDB.12.0;Data Source=“ + xlsname + “;Extended Properties=\“Excel 12.0;HDR=YES;IMEX=0\“;“;
            conn = new OleDbConnection(connstr);
            {
                using (OleDbDataAdapter da = new OleDbDataAdapter(“Select * from [Sheet1$]“ conn))//
                {
                    da.Fill(ds “excel“);
                }
            }
            alldata = ds.Tables[0];

            //MessageBox.Show(alldata.Rows.Count.ToString());
        }
        private void button1_Click(object sender EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = “EXCEL文件(*.xlsx)|*.xlsx“;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                xlsname = ofd.FileName;
            }
            string connstr = “Provider=Microsoft.ACE.OLEDB.12.0;Data Source=“ + xlsname;
            readxls(xlsname);

            DataView fist = new DataView(alldata);
            DataSet ds2 = new DataSet();
            DataTable firstcolonum = fist.ToTable(true “公司“);
            for (int i = 0; i < firstcolonum.Rows.Count; i++)
            {
                TreeNode td = new TreeNode();
                td.Text = firstcolonum.Rows[i][0].ToString();

                DataRow[] drs = alldata.Select(“[公司]=‘“ + firstcolonum.Rows[i][0].ToString() + “‘“);
                for (int j = 0; j < drs.Length; j++)
                {
                    TreeNode td1 = new TreeNode();
                    TreeNode td2 = new TreeNode();
                    TreeNode td3 = new TreeNode();
                    td1.Text = drs[j][1].ToString();
                    td2.Text = drs[j][2].ToString();
                    td3.Text = drs[j][3].ToString();
                    td.Nodes.Add(td1);
                    td1.Nodes.Add(td2);
                    td2.Nodes.Add(td3);
                }
                treeView1.Nodes.Add(td);
                }
        }
    }
}


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-10-09 17:42  .vs\
     目录           0  2020-10-09 17:42  .vs\treeview\
     目录           0  2020-10-09 17:42  .vs\treeview\v16\
     文件       26624  2020-10-09 20:22  .vs\treeview\v16\.suo
     目录           0  2020-10-09 17:42  bin\
     目录           0  2020-10-09 17:48  bin\Debug\
     文件        9728  2020-10-09 20:07  bin\Debug\treeview.exe
     文件       32256  2020-10-09 20:07  bin\Debug\treeview.pdb
     文件        2612  2020-10-09 20:07  Form1.cs
     文件        3045  2020-10-09 20:07  Form1.Designer.cs
     文件        6020  2020-10-09 20:07  Form1.resx
     目录           0  2020-10-09 17:42  obj\
     目录           0  2020-10-09 20:17  obj\Debug\
     文件         208  2020-10-09 17:42  obj\Debug\.NETframeworkVersion=v4.0.AssemblyAttributes.cs
     文件        1423  2020-10-09 20:17  obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6866  2020-10-09 17:42  obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     目录           0  2020-10-09 17:42  obj\Debug\TempPE\
     文件          42  2020-10-09 17:47  obj\Debug\treeview.csproj.CoreCompileInputs.cache
     文件         739  2020-10-09 17:48  obj\Debug\treeview.csproj.FileListAbsolute.txt
     文件        1012  2020-10-09 20:07  obj\Debug\treeview.csproj.GenerateResource.cache
     文件       10568  2020-10-09 20:17  obj\Debug\treeview.csprojAssemblyReference.cache
     文件        9728  2020-10-09 20:07  obj\Debug\treeview.exe
     文件         180  2020-10-09 20:07  obj\Debug\treeview.Form1.resources
     文件       32256  2020-10-09 20:07  obj\Debug\treeview.pdb
     文件         180  2020-10-09 17:47  obj\Debug\treeview.Properties.Resources.resources
     文件         489  2020-10-09 17:42  Program.cs
     目录           0  2020-10-09 17:42  Properties\
     文件        1308  2020-10-09 17:42  Properties\AssemblyInfo.cs
     文件        2829  2020-10-09 17:42  Properties\Resources.Designer.cs
     文件        5612  2020-10-09 17:42  Properties\Resources.resx
     文件        1095  2020-10-09 17:42  Properties\Settings.Designer.cs
............此处省略3个文件信息

评论

共有 条评论