• C# 读取注册表获取本机的全部的typelib信息


    根据本机的注册表得出结论

    
    
     1 public class MyTypeLibInfor
     2     {
     3         public string TypeLibName { get; set; }
     4         public string TypeLibGuid { get; set; }
     5         public string TypeLibWin32FullPath { get; set; }
     6         public string TypeLibWin64FullPath { get; set; }
     7         public string Description { get; set; }
     8         public MyTypeLibInfor(RegistryKey regKey)
     9         {
    10             this.TypeLibGuid = regKey.Name;
    11             var item = regKey.OpenSubKey(regKey.GetSubKeyNames()[0], false);
    12             if (item.GetValue("") != null) this.TypeLibName = item.GetValue("").ToString();
    13             if (item.OpenSubKey("0\win32", false) != null)
    14             {
    15                 if (item.OpenSubKey("0\win32", false).GetValue("") != null)
    16                 {
    17                     this.TypeLibWin32FullPath = item.OpenSubKey("0\win32", false).GetValue("").ToString();
    18                 }
    19             }
    20             if (item.OpenSubKey("0\win64", false) != null)
    21             {
    22                 if (item.OpenSubKey("0\win64", false).GetValue("") != null)
    23                 {
    24                     this.TypeLibWin64FullPath = item.OpenSubKey("0\win64", false).GetValue("").ToString();
    25                 }
    26             }
    27         }
    28     }

    主函数
     1  private void getAllTypeLibToolStripMenuItem_Click(object sender, EventArgs e)
     2         {
     3             List<MyTypeLibInfor> listTypelibs = new List<MyTypeLibInfor>();
     4             using (var clsidRootKey = Registry.ClassesRoot.OpenSubKey("TypeLib"))
     5             {
     6                 foreach (var typeLibKey in clsidRootKey.GetSubKeyNames())
     7                 {
     8                     var key = clsidRootKey.OpenSubKey(typeLibKey, false);
     9                     if (key != null) listTypelibs.Add(new MyTypeLibInfor(key));
    10                 }
    11             }
    12             if (listTypelibs.Count > 0) MycommonUility.ListClassToExcelSh(listTypelibs);
    13         }

     lsit class 转excel导出

     1  public static void ListClassToExcelSh<T>(List<T> myList)
     2         {
     3             Excel.Application xlapp = new Excel.Application();
     4             Excel.Workbook wb = xlapp.Workbooks.Add();
     5             Excel.Worksheet ws = (wb.Sheets[1]) as Excel.Worksheet;
     6             Type t = myList[0].GetType();
     7             var pros = t.GetProperties().Where(c => c.DeclaringType.IsPublic).ToArray();
     8             for (int i = 0; i < pros.Length; i++) ws.Cells[1, i + 1] = pros[i].Name;
     9             for (int i = 0; i < myList.Count; i++)
    10             {
    11                 for (int j = 0; j < pros.Length; j++) ws.Cells[i + 2, j + 1] = pros[j].GetValue(myList[i]);
    12             }
    13             ws.UsedRange.EntireColumn.AutoFit();
    14             xlapp.Visible = true;
    15             xlapp.WindowState = Excel.XlWindowState.xlMaximized;
    16         }
  • 相关阅读:
    jquery实现表格文本框淡入更改值后淡出
    硬件抽象层
    第八章读书笔记
    Linux驱动——LED闪烁
    编写Linux驱动与统计单词个数
    在开发板上安装Android
    源代码的下载和编译
    初学Git随笔
    Ubuntu Linux环境下的Android开发环境的配置
    Android系统移植于驱动开发概述
  • 原文地址:https://www.cnblogs.com/NanShengBlogs/p/13606295.html
Copyright © 2020-2023  润新知