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         }
  • 相关阅读:
    hdu 4707 Pet
    hdu 3584 Cube (三维树状数组)
    poj 2155 Matrix (树状数组)
    poj 1195 Mobile phones (树状数组)
    工厂方法模式
    简单工厂模式
    关于设计模式
    UML类图
    UML
    【转载】UML用例图
  • 原文地址:https://www.cnblogs.com/ZJ199012/p/2703581.html
Copyright © 2011-2022 走看看