zoukankan      html  css  js  c++  java
  • 向Excel模板中添加数据

      /// <summary>
            /// 追加记录
            /// </summary>
            /// <param name="DataTable"></param>
            public void AppendText(string fileName, System.Data.DataTable dt)
            {
                ApplicationClass excel = new ApplicationClass();
                object miss = System.Type.Missing;
                excel.Workbooks.Open(fileName, miss, false, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss,         miss, miss);
                Workbooks workBooks = null;
                try
                {
                    workBooks = excel.Workbooks;
                    Workbook curWorkBook = workBooks[1];
                    Worksheet curSheet = (Worksheet)curWorkBook.Worksheets[1];
                    excel.DisplayAlerts = false;
                    excel.AlertBeforeOverwriting = false;

                    int cout = curSheet.UsedRange.Rows.Count;
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        //for (int j = 0; j < dt.Columns.Count; j++)
                        //{
                        curSheet.Cells[cout + i + 1, 1] = (cout + i - 2).ToString();
                        curSheet.Cells[cout + i + 1, 2] = dt.Rows[i][0].ToString();
                        
                        //}
                    }
                    curWorkBook.Save();
                    workBooks.Close();
                    excel.Quit();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if (workBooks != null) { workBooks.Close(); }
                    if (excel != null) { excel.Quit(); }
                }
            }

  • 相关阅读:
    负margin实现div的左右排版
    一起来灭掉IE6!
    javac编译多个带package文件
    iis express感觉还不错
    关于sqlite使用entity framework的布署问题
    远程服务器返回了错误 NOTFOUND
    userAgent string detection in javascript
    a crossbroswer solution for parse xml fragment
    event related object in javascript
    several way to implement inheritance in javascript
  • 原文地址:https://www.cnblogs.com/fang8206/p/2024555.html
Copyright © 2011-2022 走看看