<head runat="server">
<title></title>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
function getExecl() {
$.ajax({
type: 'POST',
url: 'ashx/execl.ashx',
success: function (data) {
var re = eval(data);
for (var i in re) {
if (re[i].num > )
alert(re[i].num);
}
},
error: function (data) { }
}); } </script>
</head>

前台代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Office.Interop.Excel;
using System.Runtime.InteropServices;
using System.Web.Script.Serialization; namespace WebApplication1.ashx
{
/// <summary>
/// Summary description for execl
/// </summary>
public class execl : IHttpHandler
{
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);
JavaScriptSerializer json = new JavaScriptSerializer();
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
int s= getExecl();
MessageInfo MessageRe = new MessageInfo(s, null);
string returnValue = json.Serialize(MessageRe);
returnValue = "[" + returnValue + "]";
context.Response.Write(returnValue);
}
private int getExecl()
{
int num = ;
try
{
ApplicationClass excel = new ApplicationClass();
string time = DateTime.Now.ToString("yyyyMMddHHmmss");
string path = @"H:\exel\" + time + ".xlsx";
excel.Workbooks.Open(@"H:\exel\1.xlsx", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
excel.Visible = false; //设置可见性
Worksheet workshet = (Worksheet)excel.Worksheets.get_Item();
workshet.Cells[, ] = ""; //行和列
workshet.Cells[, ] = "";
workshet.Cells[, ] = "";
workshet.Cells[, ] = "";
workshet.SaveAs(path, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
excel.Quit(); //退出
IntPtr t = new IntPtr(excel.Hwnd); //运用句柄
int k = ;
GetWindowThreadProcessId(t, out k);
System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(k);
p.Kill(); //杀死当前进程
num = ;
}
catch (Exception e) { }
return num;
}
public bool IsReusable
{
get
{
return false;
}
}
} }

一般处理程序代码

参考了地址 http://www.cnblogs.com/zhangchenliang/archive/2011/07/21/2112430.html

asp.net读取execl模板并填充数据,关闭进程的更多相关文章

  1. 读取word模板,填充数据后导出

    一.需求说明 定期生成word报告,报告中含有文本.表格.图表等元素,依次获取进行替换,保留原有样式,生成新的word文档 二.引入依赖 <dependency> <groupId& ...

  2. poi读取excel模板,填充内容并导出,支持导出2007支持公式自动计算

    /** * 版权所有(C) 2016 * @author www.xiongge.club * @date 2016-12-7 上午10:03:29 */ package xlsx; /** * @C ...

  3. Itext读取PDF模板文件渲染数据后创建新文件

    Maven导入依赖 <properties> <itextpdf.version>5.5.0</itextpdf.version> <itext-asian. ...

  4. 向Word模板中填充数据

    现在有这样的需求,给Word文档的指定位置填充上特定数据,例如我们有一个终端,用来打印员工的薪资证明,对于一个公司来说,他的薪资证明模板是固定的,变化的地方是员工姓名,部门,职位等.我们只需要将这些指 ...

  5. C# 创建execl文件 并且填充数据

    第一步:引用文件 using NPOI.HSSF.UserModel;using System.Data;using CTUClassLibrary;using System.IO;using NPO ...

  6. js使用模板快速填充数据

    1.html <!DOCTYPE html> <html> <head> <title>模板标签</title> </head> ...

  7. [转载]java向word模板中填充数据(总结)

    使用过PageOffice动态生成word文档的人都知道,PageOffice可以给word文档的指定位置进行填充,这里我们所说的指定位置在PageOffice的专业术语里面有两个概念,一个叫做数据区 ...

  8. [原创]java向word模板中填充数据(总结)

    使用过PageOffice动态生成word文档的人都知道,PageOffice可以给word文档的指定位置进行填充,这里我们所说的指定位置在PageOffice的专业术语里面有两个概念,一个叫做数据区 ...

  9. POI往word模板中写入数据

    转: POI往word模板中写入数据 2018年03月24日 16:00:22 乄阿斗同學 阅读数:2977  版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn ...

随机推荐

  1. RHEL 5.7 Yum配置本地源[Errno 2] No such file or directory

    在Red Hat Enterprise Linux Server release 5.7 上配置YUM本地源时,遇到了"Errno 5] OSError: [Errno 2] No such ...

  2. 如何区分/dev/input/event

    方法是把每一个/dev/input/event打开.通过ioctl函数来读取设备name,每一个设备name是固定的,可以根据name区分event.我这是查找触摸事件为例:代码如下: static ...

  3. 如何使用 Entity Framework 构造动态查询表达式

    一般的程序员做上几年以后, 或多或少的都有些代码的积累, 我也不例外. 作为微软技术程序员, 自从Linq和EF出来之后, 就基本上爱不释手了, 且不说执行效率的问题, 单单就开发效率和代码的可移植性 ...

  4. Dan Zhang - Visual Studio ALM MVP

    I am a Microsoft Certified Partner specialising in .NET solutions, also worked as an ALM consultant. ...

  5. 常用算法——排序(三)

    希尔排序法 希尔排序又称为缩小增量排序,也属于插入排序类的算法,是对直接插入排序的一种改进. 基本思想就是:将需要排序的序列划分为若干个较小的序列,对这些序列进行直接插入排序,通过这样的操作可使用需要 ...

  6. Linux 之 目录和文件

    1  初识 1.1  终端 打开终端: Ctrl + Alt + F1 ~ F6 图形界面: Ctrl + Alt + F7 1.2  命令 1)  一般 date; cal - calendar; ...

  7. POJ2505 A multiplication game[博弈论]

    A multiplication game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6028   Accepted:  ...

  8. Google Material Design的图标字体使用教程

    使用教程 1. 打开Material icons下载页 2. 选择要下载的图标 (目前不能多选>_<) 3.选择要下载的格式即可 图标字体使用教程 [方法一] STEP 1: 引入字体文件 ...

  9. python3循环语句while

    Python的循环语句有for和while语句,这里讲while语句. Python中while语句的一般形式: while 条件判断 : 语句 需要注意冒号和缩进.另外,注意Python中没有do. ...

  10. iOS Photos.framework框架

    链接: iOS8.0 使用Photos.framework对相册的常用操作 iOS AssetsLibrary和Photos的使用总结: 权限及相册的获取 iOS 开发之照片框架详解 iOS Asse ...