zoukankan      html  css  js  c++  java
  • 将数据导入指定的Excel模版中

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.OracleClient;
    using Microsoft.Office.Interop.Excel;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;

    private void Excel_data()

    {

            System.DateTime MINI = System.DateTime.Now;
            string times = MINI.ToString("yyyy-MM-dd HH:mm:ss");       
            Session["times"] = times.ToString();
            string dayin_times = MINI.ToString("yyyy-MM-dd HH:mm");       

            string path = Server.MapPath("/web/Product/Web/Sample/faliaobiao.xls");
            string excelPath = Server.MapPath("/web/" + Guid.NewGuid() + ".xls");
            
            ExcelHander OpenFile = new ExcelHander();
            OpenFile.OpenExcelFile(path);
            Worksheet datasheet = null;
            Sheets sheets = OpenFile.CurrentWorkBooks[1].Worksheets;
            foreach (Worksheet sheet in sheets)
            {
                if (sheet.Name == "Sheet1")
                {
                    datasheet = sheet;
                    break;
                }
            }
            datasheet.Cells[1, 14] = dayin_times.ToString().Trim();
            datasheet.Cells[3, 2] = lblmateriel_id.Text.Trim().ToString() +"   "+lblmateriel_name.Text.Trim().ToString();
            datasheet.Cells[3, 12] = lblstart_date.Text.Trim().ToString();
            datasheet.Cells[3, 7] = lblworkorder.Text.Trim().ToString();
            datasheet.Cells[3, 10] = lblnum.Text.Trim().ToString();
                int colIndex = 1, rowIndex = 5;
                foreach (DataRow row in Table1.Rows)
                {
                    rowIndex++; colIndex = 0;
                    foreach (DataColumn col in Table1.Columns)
                    {
                        colIndex++;
                        if (colIndex == 0)
                        {
                            datasheet.Cells[rowIndex, colIndex] = "'" + row[col.ColumnName].ToString();
                        }
                        else
                        {
                            datasheet.Cells[rowIndex, colIndex] = row[col.ColumnName].ToString();
                        }
                    }
                }
            OpenFile.SaveAs(excelPath);
            sheets = null;
            OpenFile.ReleaseExcel();
            OpenFile.KillAllExcelApp();
               
            Response.End();

    }

  • 相关阅读:
    Vim的行号、语法显示等设置,即.vimrc文件的配置
    Vim 配置详解
    经典SQL语句大全
    几种流行的AJAX框架jQuery,Mootools,Dojo,Ext JS的对比
    GHOST XP SP3无法安装IIS服务的解决方法
    开发中巧用Enum枚举类型
    代码的坏味道
    C#转义字符
    Dijit、ExtJS、jQuery UI 异同浅析
    未雨绸缪 Plan to Throw One Away
  • 原文地址:https://www.cnblogs.com/lovewife/p/1396319.html
Copyright © 2011-2022 走看看