• VSTO的简单用法


    一直听说vsto这个名词,还真不知道什么意思,今天了解了一下,原来他的全程是Visual Studio Tools For Office,说他是VBA的替身(VBA俺也不是很懂),刚才上网查询做了个例子,我把代码贴出来

    第一步:导入DLL

    要用到第三方插件,路径在:X:Program Files Microsoft Visual Studio [10.0|11.0|12.0]Visual Studio Tools for OfficePIAOffice[13|14|15]Microsoft.Office.Interop.Excel.dll

    第二步:代码实现

     1  string excelFilePath = string.Format("{0}ExcelTest1.xlsx", AppDomain.CurrentDomain.BaseDirectory);
     2             using (ExcelHandler handler = new ExcelHandler(excelFilePath, false)) 
     3             {
     4                 handler.OpenOrCreate();
     5                 handler.DeleteWorksheet("TestSheet1");
     6                 //创建一个Worksheet
     7                 Worksheet sheet = handler.AddWorksheet("TestSheet1");
     8                 //A1-E5
     9                 Range range = handler.GetRange(sheet, 1, 1, 5, 5);
    10                 handler.SetRangeFormat(range);
    11                 range.Font.Bold = true;//加粗
    12                 System.Data.DataTable table = new System.Data.DataTable();
    13                 table.Columns.AddRange(new DataColumn[] { new DataColumn("列1"), new DataColumn("列2"), new DataColumn("列3") });
    14                 Random random = new Random(20);
    15                 for (int i = 0; i < 10; i++)
    16                 {
    17                     table.Rows.Add(random.Next(100), random.Next(100), random.Next(100));
    18                 }
    19                 //导入数据
    20                 handler.ImportDataTable(sheet, "导入表格", true, new string[] { "列1", "列2", "列3" }, 1, 1, table);
    21                 handler.Save();
    22             }
  • 相关阅读:
    Redis简介 安装 注册服务
    Supervisor Linux守护进程
    .Net5 控制台 读取配置文件+依赖注入
    Linux Gdip
    Net Core封装 踩坑
    Apollo 公共Namespace使用json
    Visual Studio 2019修改项目名
    【面向对象】--静态类与非静态类的区别
    win10设置默认中英文符号【程序员标配】
    MySQL 数据库访问驱动-版本问题
  • 原文地址:https://www.cnblogs.com/xuguoming/p/3421088.html
Copyright © 2020-2023  润新知