• 将数据导入指定的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();

    }

  • 相关阅读:
    与平面和空间打交道的计算几何
    借助水流解决问题的网络流
    计算几何算法概览
    关于while (~scanf("%d %d", &m, &n))的用法
    Minimizing maximizer(POJ 1769)
    java九九乘法表
    java替换字符串中的World为Money
    java截取字符串,第4位以后的字符串用*代替
    java使用valueOf的方法反转字符串输出
    java使用StringBuilder的方法反转字符串输出
  • 原文地址:https://www.cnblogs.com/lovewife/p/1396319.html
Copyright © 2020-2023  润新知