個人最近做的最多的重複工作就是excel导出
//导出事件,这个是有合并动态列的 double num1 = 0, num2 = 0, num3 = 0;
protected void btnExcel_Click(object sender, ImageClickEventArgs e)
{
num1 = 0; num2 = 0; num3 = 0;
DirectoryInfo fdir = new DirectoryInfo(Server.MapPath(@"\TmpReport"));
FileInfo[] files = fdir.GetFiles();
for (int i = 0; i < files.Length - 1; i++)
{
if (files[i].Name.IndexOf("tmp") >= 0)
{
try
{
files[i].Delete();
}
catch (Exception ex)
{
}
}
}
string time = DateTime.Now.ToString("yyyyMMddHHmmss");
FileInfo fi = new FileInfo(Server.MapPath(@"\Excel\每日信貸報告.xls"));
fi.CopyTo(Server.MapPath(@"\TmpReport\tmp" + time + ".xls"));
Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbooks workbooks = xlApp.Workbooks;
Microsoft.Office.Interop.Excel.Workbook xlBook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
Microsoft.Office.Interop.Excel.Worksheet xlSheet = new Microsoft.Office.Interop.Excel.Worksheet();
xlBook = xlApp.Workbooks.Open(Server.MapPath(@"\TmpReport\tmp" + time + ".xls"));
xlSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlBook.Worksheets.get_Item(1);
int tmpid = 2;
string rowSheet = "";
string 可簽額 = "";
string 戶主名 = "";
int count1 = 2;
int count2 = 2;
int Colorindex = 0;
for (int i = 0; i < dtList.Rows.Count; i++)
{
string rowSheet1 = Convert.ToString(dtList.Rows[i]["戶號"]);
if (rowSheet1 == rowSheet)
{
//xlSheet.Cells[tmpid, 1] = "";
//xlSheet.Cells[tmpid, 2] = "";
//xlSheet.Cells[tmpid, 3] = "";
}
else
{
if (rowSheet != "")
{
Microsoft.Office.Interop.Excel.Range integral = (Microsoft.Office.Interop.Excel.Range)xlSheet.get_Range("A" + count1, "A" + (count2 - 1));
integral.MergeCells = true;
integral.Value = 可簽額;
integral.Font.Size = 16;
integral.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
integral.VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;
Microsoft.Office.Interop.Excel.Range integral1 = (Microsoft.Office.Interop.Excel.Range)xlSheet.get_Range("B" + count1, "B" + (count2 - 1));
integral1.MergeCells = true;
integral1.Value = rowSheet;
integral1.Font.Size = 16;
// integral1.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;
integral1.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
integral1.VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;
Microsoft.Office.Interop.Excel.Range integral2 = (Microsoft.Office.Interop.Excel.Range)xlSheet.get_Range("C" + count1, "C" + (count2 - 1));
integral2.MergeCells = true;
integral2.Value = 戶主名;
integral2.Font.Size = 16;
integral2.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
integral2.VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;
Colorindex = 15;
if (Colorindex != 0)
{
Microsoft.Office.Interop.Excel.Range integrals = (Microsoft.Office.Interop.Excel.Range)xlSheet.get_Range("a" + tmpid, "I" + tmpid);
integrals.Interior.ColorIndex = 15;
Colorindex = 0;
}
count2++;
tmpid++;
count1 = count2;
//xlSheet.Cells[tmpid, 1] = dtList.Rows[i]["可簽額"];
//xlSheet.Cells[tmpid, 2] = dtList.Rows[i]["戶號"];
//xlSheet.Cells[tmpid, 3] = dtList.Rows[i]["戶主名"];
}
rowSheet = rowSheet1;
可簽額 = Convert.ToString(dtList.Rows[i]["可簽額"]);
戶主名 = Convert.ToString(dtList.Rows[i]["戶主名"]);
}
num1 += Convert.ToDouble(dtList.Rows[i]["貸款額"].ToString());
num2 += Convert.ToDouble(dtList.Rows[i]["還款額"].ToString());
num3 += Convert.ToDouble(dtList.Rows[i]["餘額"].ToString());
xlSheet.Cells[tmpid, 4] = dtList.Rows[i]["借款人"];
xlSheet.Cells[tmpid, 5] = dtList.Rows[i]["單編號"];
double a = Convert.ToDouble(dtList.Rows[i]["貸款額"].ToString());
double b = Convert.ToDouble(dtList.Rows[i]["還款額"].ToString());
double c = Convert.ToDouble(dtList.Rows[i]["餘額"].ToString());
string aStr = "", bStr = "", cStr = "";
if (a != 0)
{
aStr = a.ToString("#,##0.####");
}
if (b != 0)
{
bStr = b.ToString("#,##0.####");
}
if (c != 0)
{
cStr = c.ToString("#,##0.####");
}
xlSheet.Cells[tmpid, 6] = aStr;
xlSheet.Cells[tmpid, 7] = bStr;
xlSheet.Cells[tmpid, 8] = cStr;
xlSheet.Cells[tmpid, 9] = dtList.Rows[i]["下單號"];
tmpid = tmpid + 1;
count2++;
}
Microsoft.Office.Interop.Excel.Range integral3 = (Microsoft.Office.Interop.Excel.Range)xlSheet.get_Range("A" + count1, "A" + (count2 - 1));
integral3.MergeCells = true;
integral3.Value = 可簽額;
integral3.Font.Size = 16;
integral3.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
integral3.VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;
Microsoft.Office.Interop.Excel.Range integral4 = (Microsoft.Office.Interop.Excel.Range)xlSheet.get_Range("B" + count1, "B" + (count2 - 1));
integral4.MergeCells = true;
integral4.Value = rowSheet;
integral4.Font.Size = 16;
integral4.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
integral4.VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;
Microsoft.Office.Interop.Excel.Range integral5 = (Microsoft.Office.Interop.Excel.Range)xlSheet.get_Range("C" + count1, "C" + (count2 - 1));
integral5.MergeCells = true;
integral5.Value = 戶主名;
integral5.Font.Size = 16;
integral5.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
integral5.VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;
//獲取行
Microsoft.Office.Interop.Excel.Range rg = (Microsoft.Office.Interop.Excel.Range)xlSheet.Cells[tmpid, 1];
rg = (Microsoft.Office.Interop.Excel.Range)xlSheet.Cells[tmpid, 1];
rg.Interior.ColorIndex = 15;
rg = (Microsoft.Office.Interop.Excel.Range)xlSheet.Cells[tmpid, 2];
rg.Interior.ColorIndex = 15;
rg = (Microsoft.Office.Interop.Excel.Range)xlSheet.Cells[tmpid, 3];
rg.Interior.ColorIndex = 15;
rg = (Microsoft.Office.Interop.Excel.Range)xlSheet.Cells[tmpid, 4];
rg.Interior.ColorIndex = 15;
rg = (Microsoft.Office.Interop.Excel.Range)xlSheet.Cells[tmpid, 5];
rg.Interior.ColorIndex = 15;
rg = (Microsoft.Office.Interop.Excel.Range)xlSheet.Cells[tmpid, 6];
rg.Interior.ColorIndex = 15;
rg = (Microsoft.Office.Interop.Excel.Range)xlSheet.Cells[tmpid, 7];
rg.Interior.ColorIndex = 15;
rg = (Microsoft.Office.Interop.Excel.Range)xlSheet.Cells[tmpid, 8];
rg.Interior.ColorIndex = 15;
rg = (Microsoft.Office.Interop.Excel.Range)xlSheet.Cells[tmpid, 9];
rg.Interior.ColorIndex = 15;
xlSheet.Cells[tmpid, 1] = "";
xlSheet.Cells[tmpid, 2] = "";
xlSheet.Cells[tmpid, 3] = "";
xlSheet.Cells[tmpid, 4] = "";
xlSheet.Cells[tmpid, 5] = "合計:";
xlSheet.Cells[tmpid, 6] = num1.ToString("#,##0.####");
xlSheet.Cells[tmpid, 7] = num2.ToString("#,##0.####");
xlSheet.Cells[tmpid, 8] = num3.ToString("#,##0.####");
xlSheet.SaveAs(Server.MapPath(@"\TmpReport\tmp" + time + "1.xls"));
xlBook.Close();
xlApp.Quit();
Response.Expires = 0;
Response.Clear();
Response.Buffer = true;
Response.Charset = "utf-8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("每日信貸報告.xls"));
Response.WriteFile(Server.MapPath(@"\TmpReport\tmp" + time + "1.xls"));
Response.Flush();
Response.Clear();
}
個人最近做的最多的重複工作就是excel导出的更多相关文章
- Oracle运维 专业的事情交给专业的人来做
关于Oracle运维的重要性,随便写了几句,放在这儿和大家共勉. Oracle数据库在RDBMS中独占熬头,07年统计其市场份额占关系数据库市场的48.6%稳居首位,而且逐年增加,上升势头强劲.在使用 ...
- [原创]浅谈IT人如何做理财规划
[原创]浅谈IT人如何做理财规划 鱼哥博客上多数写的是技术和管理相关,但很少有理财等话题,今天抽空来谈谈IT人如何做理财规划,如果要想学习理财,我想很有名的“标准普尔家庭资产象限图”上值得每个学习和理 ...
- (转)Groupon前传:从10个月的失败作品修改,1个月找到成功 并不挶泥在这个点子上面,它反而往后站一步,看看他们已经做好的这个网站,可以再怎么包装成另一个完完全全不同的网站?所有的人所做的每件失败的事情中, 一定有碰到或含有成功的答案」在里面,只是他们不知道而已。 人不怕失败」,只怕宣布失败」
(转)Groupon前传:从10个月的失败作品修改,1个月找到成功 今天读到 一个非常励志人心的故事 ,就像现在「叶问」有「前传」,最近很火红的团集购网站Groupon 也出现了「Groupon前传」 ...
- 在做excel导出时如何将excel直接写在输出流中
之前做excel导出时,我都是先将文件写在服务器上,然后再下载下来,后来发现原来可以直接将文件写在输出流里边. 下面是一个小demo: package com.huaqin.fcstrp.util; ...
- [ASP.NET] 使用Loading遮罩防止使用者重複點擊
From: http://www.dotblogs.com.tw/joysdw12/archive/2012/12/13/85629.aspx 前言 在網頁執行中可能會因為資料量大或其他原因影響使用者 ...
- 【EXCEL】簡単に重複探し
下記のような表があって.重複があるかどうか探すのが大変と思いますが. 簡単に重複探す方法を紹介します. Step1.重複を探す(例えこちらでは項目)を選択します. Step2.メニューで 条件付き書式 ...
- 平时没有怎么用Excel做 加减乘除 计算,猛地发现,其实Excel 是一个很好的简单计算器
平时没有怎么用Excel做 加减乘除 计算,猛地发现,其实Excel 是一个很好的简单计算器
- SQL Sever 刪除重複數據只剩一條
use book go create table ##T1( n int, a nvarchar(20) ) --查詢重複記錄,插入臨時表 insert into ##T1(n,a) select s ...
- 为啥我做的RFM模型被人说做错了,我错哪了?
本文转自知乎 作者:接地气的陈老师 ————————————————————————————————————————————————————— 有同学问:“为啥我做的RFM模型被客户/业务部门批斗,说 ...
随机推荐
- hadoop2的伪分布部署
通过我们前面的操作,已经可以编译并且打包产生适合本机的hadoop包,目录是/usr/local/hadoop-2.2.0-src/hadoop-dist/target/hadoop-2.2.0. 使 ...
- Android 第三方应用接入微信平台(1)
关键字:微信开放平台 Android第三方应用接入微信 微信平台开放后倒是挺火的,许多第三方应用都想试下接入微信这个平台, 毕竟可以利用微信建立起来的关系链来拓展自己的应用还是挺不错的,可 以节约 ...
- jQuery实例-记住登录信息
本文介绍下jquery 记住登录信息的方法,引入jquery.cookie.js文件,实现记住登录信息,有需要的朋友参考下. 首先,导入jquery.cookie.js $(function(){ / ...
- 瞎折腾之 VS2013 Cordova项目的创建与配置
扯淡 什么是Cordova ? 网上查询的说明: Cordova是贡献给Apache后的开源项目,是从PhoneGap中抽出的核心代码,是驱动PhoneGap的核心引擎.你可以把他想象成类似于Webk ...
- 使用MFC中的AfxBeginThread创建多线程
创建一个基于对话框的工程,工程名为CreateThreadRect 在CreateThreadRect.cpp中增加一个ThreadProc函数,代码如下 工作者线程的函数必须是全局函数或静态 ...
- windowsUI的总结
1,MFC 基于VC6.0的微软基础库 2,WPF 做绚丽界面一律用WPF,做一般绚丽界面用WinForm,做windows标准界面用MFC WPF也有个致命缺点,就是要.net framework支 ...
- VS启用IIS调试的方法及可能碰到的问题。
经常有这种情况, 开发机本地正常, 但是一旦发布到服务上后, 就出现各种问题. 这是由于开发机和服务器环境不一样造成的, 所以开发时要尽可能的模拟真实性. 这时候, VS的这个功能就帮大忙了. 如何 ...
- POJ 1201 Intervals (差分约束系统)
题意 在区间[0,50000]上有一些整点,并且满足n个约束条件:在区间[ui, vi]上至少有ci个整点,问区间[0, 50000]上至少要有几个整点. 思路 差分约束求最小值.把不等式都转换为&g ...
- POJ 2724 Purifying Machine (二分图匹配)
题意 给定m个长度为n的01串(*既表示0 or 1.如*01表示001和101).现在要把这些串都删除掉,删除的方法是:①一次删除任意指定的一个:②如果有两个串仅有一个字符不同,则可以同时删除这两个 ...
- Linux下安装Android Studio(ubuntu)
一. 安装Android Studio 1. 添加源,按回车键继续 sudo apt-add-repository ppa:paolorotolo/android-studio 2. 更新源 sudo ...