zoukankan      html  css  js  c++  java
  • 利用NPOI修改Excel文件

    private void button6_Click(object sender, EventArgs e)
    {
    //string FileName = @"D:Excel2007-1019.xlsx";
    string FileName = @"D:Excel2003-1102.xls";

    if (!File.Exists(FileName))
    {
    return;
    }

    if (
    (FileName.ToUpper().IndexOf(".xlsx".ToUpper()) < 0)
    && (FileName.ToUpper().IndexOf(".xls".ToUpper()) < 0)
    )
    {
    return;
    }


    IWorkbook wk = null;
    using (FileStream fs = File.Open(FileName, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite))
    {
    if (FileName.ToUpper().IndexOf(".xlsx".ToUpper()) > 0)
    {
    wk = new XSSFWorkbook(fs);
    }
    else
    {
    wk = new HSSFWorkbook(fs);
    }
    }

    ISheet sheet = wk.GetSheetAt(0);
    if (wk.GetSheetAt(0) == null)
    {
    sheet = wk.CreateSheet();
    }

    // 在现有行的下面添加一些数据
    int startRow = sheet.LastRowNum + 1;


    IRow row = sheet.CreateRow(startRow);
    row.CreateCell(0).SetCellValue("创建时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
    row.CreateCell(1).SetCellValue("中");
    row.CreateCell(2).SetCellValue("国");
    row.CreateCell(3).SetCellValue("南");
    row.CreateCell(4).SetCellValue("海");


    using (FileStream fileStream = File.Open(FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
    {
    wk.Write(fileStream);
    }

    }

  • 相关阅读:
    iOS 11 application 新特性
    Swift循环遍历集合方法
    Swift 使用 #warning
    swift 3.0 正则表达式查找/替换字符
    App Store 审核指南
    iOS 获取设备的各种信息的方法
    闭包(Closure)
    Swift的Guard语句
    Swift 学习指引
    Swift 4.0 废弃的柯里化
  • 原文地址:https://www.cnblogs.com/LongHuaiYu/p/5692077.html
Copyright © 2011-2022 走看看