zoukankan      html  css  js  c++  java
  • 创建 Excel 表格

    View Code
     1 //创建excel
     2         public void CreateExcel(string tableName, string tableType , List<HNFatherAddress> list)
     3         {
     4             object missing = System.Reflection.Missing.Value;
     5             MSExcel.Application app = new MSExcel.Application();
     6             app.Application.Workbooks.Add(true);
     7             MSExcel.Workbook book = (MSExcel.Workbook)app.ActiveWorkbook;
     8             MSExcel.Worksheet sheet = (MSExcel.Worksheet)book.ActiveSheet;
     9             //第一行
    10             sheet.Cells[1, 1] = "table";
    11             sheet.Cells[1, 2] = tableName;
    12             sheet.Cells[1, 3] = tableType;
    13 
    14             //第二行
    15             sheet.Cells[2, 1] = "编号";
    16             sheet.Cells[2, 2] = "地址";
    17             sheet.Cells[2, 3] = "类型";
    18 
    19             int count = 2;
    20 
    21             foreach (HNFatherAddress item in list)
    22             {
    23                 count = count + 1;
    24                 sheet.Cells[count, 1] = "num";
    25                 sheet.Cells[count, 2] = item.FatherName;
    26                 sheet.Cells[count, 3] = item.FatherType;
    27                 
    28             }
    29             //保存
    30             SaveFileDialog save = new SaveFileDialog();
    31             save.Filter = "Excel(*.xls)|*.xls";
    32             save.ShowDialog();
    33 
    34             string savePath = save.FileName;
    35             book.SaveCopyAs(savePath);
    36             book.Close(false, missing, missing);
    37 
    38             app.Quit();
    39         }
  • 相关阅读:
    03 Logistic Regression
    01 Linear Regression with One Variable
    00 Introduction
    virsh使用
    Linux配置输入设备(如停用笔记本键盘)
    linux安装ipconfig等网络工具
    软件工程团队第五次作业
    团队第四次作业
    软件工程团队第三次作业
    软件工程团队第二次作业
  • 原文地址:https://www.cnblogs.com/ZJ199012/p/2703581.html
Copyright © 2011-2022 走看看