复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Web;
using Excel = Microsoft.Office.Interop.Excel;
/// <summary>
///ExcelClass 的摘要说明
/// </summary>
public class ExcelClass
{
/// <summary>
/// 构建ExcelClass类
/// </summary>
public ExcelClass()
{
this.m_objExcel = new Excel.Application();
}
/// <summary>
/// 构建ExcelClass类
/// </summary>
/// <param name="objExcel">Excel.Application</param>
public ExcelClass(Excel.Application objExcel)
{
this.m_objExcel = objExcel;
}
/// <summary>
/// 列标号
/// </summary>
private string AList = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/// <summary>
/// 获取描述区域的字符
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public string GetAix(int x, int y)
{
char[] AChars = AList.ToCharArray();
if (x >= 26) { return ""; }
string s = "";
s = s + AChars[x - 1].ToString();
s = s + y.ToString();
return s;
}
/// <summary>
/// 给单元格赋值1
/// </summary>
/// <param name="x">行号</param>
/// <param name="y">列号</param>
/// <param name="align">对齐(CENTER、LEFT、RIGHT)</param>
/// <param name="text">值</param>
public void setValue(int y, int x, string align, string text)
{
Excel.Range range = sheet.get_Range(this.GetAix(x, y), miss);
range.set_Value(miss, text);
if (align.ToUpper() == "CENTER")
{
range.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
}
if (align.ToUpper() == "LEFT")
{
range.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
}
if (align.ToUpper() == "RIGHT")
{
range.HorizontalAlignment = Excel.XlHAlign.xlHAlignRight;
}
}
/// <summary>
/// 给单元格赋值2
/// </summary>
/// <param name="x">行号</param>
/// <param name="y">列号</param>
/// <param name="text">值</param>
public void setValue(int y, int x, string text)
{
Excel.Range range = sheet.get_Range(this.GetAix(x, y), miss);
range.set_Value(miss, text);
}
/// <summary>
/// 给单元格赋值3
/// </summary>
/// <param name="x">行号</param>
/// <param name="y">列号</param>
/// <param name="text">值</param>
/// <param name="font">字符格式</param>
/// <param name="color">颜色</param>
public void setValue(int y, int x, string text, System.Drawing.Font font, System.Drawing.Color color)
{
this.setValue(x, y, text);
Excel.Range range = sheet.get_Range(this.GetAix(x, y), miss);
range.Font.Size = font.Size;
range.Font.Bold = font.Bold;
range.Font.Color = color;
range.Font.Name = font.Name;
range.Font.Italic = font.Italic;
range.Font.Underline = font.Underline;
}
/// <summary>
/// 插入新行
/// </summary>
/// <param name="y">模板行号</param>
public void insertRow(int y)
{
Excel.Range range = sheet.get_Range(GetAix(1, y), GetAix(25, y));
range.Copy(miss);
range.Insert(Excel.XlDirection.xlDown, miss);
range.get_Range(GetAix(1, y), GetAix(25, y));
range.Select();
sheet.Paste(miss, miss);
}
/// <summary>
/// 把剪切内容粘贴到当前区域
/// </summary>
public void past()
{
string s = "a,b,c,d,e,f,g";
sheet.Paste(sheet.get_Range(this.GetAix(10, 10), miss), s);
}
/// <summary>
/// 设置边框
/// </summary>
/// <param name="x1"></param>
/// <param name="y1"></param>
/// <param name="x2"></param>
/// <param name="y2"></param>
/// <param name="Width"></param>
public void setBorder(int x1, int y1, int x2, int y2, int Width)
{
Excel.Range range = sheet.get_Range(this.GetAix(x1, y1), miss);
((Excel.Range)range.Cells[x1, y1]).ColumnWidth = Width;
}
public void mergeCell(int x1, int y1, int x2, int y2)
{
Excel.Range range = sheet.get_Range(this.GetAix(x1, y1), this.GetAix(x2, y2));
range.Merge(true);
}
public Excel.Range getRange(int x1, int y1, int x2, int y2)
{
Excel.Range range = sheet.get_Range(this.GetAix(x1, y1), this.GetAix(x2, y2));
return range;
}
private object miss = Missing.Value; //忽略的参数OLENULL
private Excel.Application m_objExcel;//Excel应用程序实例
private Excel.Workbooks m_objBooks;//工作表集合
private Excel.Workbook m_objBook;//当前操作的工作表
private Excel.Worksheet sheet;//当前操作的表格
public Excel.Worksheet CurrentSheet
{
get
{
return sheet;
}
set
{
this.sheet = value;
}
}
public Excel.Workbooks CurrentWorkBooks
{
get
{
return this.m_objBooks;
}
set
{
this.m_objBooks = value;
}
}
public Excel.Workbook CurrentWorkBook
{
get
{
return this.m_objBook;
}
set
{
this.m_objBook = value;
}
}
/// <summary>
/// 打开Excel文件
/// </summary>
/// <param name="filename">路径</param>
public void OpenExcelFile(string filename)
{
UserControl(false);
m_objExcel.Workbooks.Open(filename, miss, miss, miss, miss, miss, miss, miss,
miss, miss, miss, miss, miss, miss, miss);
m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;
m_objBook = m_objExcel.ActiveWorkbook;
sheet = (Excel.Worksheet)m_objBook.ActiveSheet;
}
public void UserControl(bool usercontrol)
{
if (m_objExcel == null) { return; }
m_objExcel.UserControl = usercontrol;
m_objExcel.DisplayAlerts = usercontrol;
m_objExcel.Visible = usercontrol;
}
public void CreateExceFile()
{
UserControl(false);
m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;
m_objBook = (Excel.Workbook)(m_objBooks.Add(miss));
sheet = (Excel.Worksheet)m_objBook.ActiveSheet;
}
public void SaveAs(string FileName)
{
m_objBook.SaveAs(FileName, miss, miss, miss, miss,
miss, Excel.XlSaveAsAccessMode.xlNoChange,
Excel.XlSaveConflictResolution.xlLocalSessionChanges,
miss, miss, miss, miss);
//m_objBook.Close(false, miss, miss);
}
public void ReleaseExcel()
{
m_objExcel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject((object)m_objExcel);
System.Runtime.InteropServices.Marshal.ReleaseComObject((object)m_objBooks);
System.Runtime.InteropServices.Marshal.ReleaseComObject((object)m_objBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject((object)sheet);
m_objExcel = null;
m_objBooks = null;
m_objBook = null;
sheet = null;
GC.Collect();
}
public bool KillAllExcelApp()
{
try
{
if (m_objExcel != null) // isRunning是判断xlApp是怎么启动的flag.
{
m_objExcel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objExcel);
//释放COM组件,其实就是将其引用计数减1
//System.Diagnostics.Process theProc;
foreach (System.Diagnostics.Process theProc in System.Diagnostics.Process.GetProcessesByName("EXCEL"))
{
//先关闭图形窗口。如果关闭失败...有的时候在状态里看不到图形窗口的excel了,
//但是在进程里仍然有EXCEL.EXE的进程存在,那么就需要杀掉它:p
if (theProc.CloseMainWindow() == false)
{
theProc.Kill();
}
}
m_objExcel = null;
return true;
}
}
catch
{
return false;
}
return true;
}
}
/// <summary>
/// 点击打印按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Sendbu_Click(object sender, EventArgs e)
{
try
{
//查找部门分类用户
DataTable Duser = EduOA.DBUtility.DbHelperSQL.Query("select count(*) as count,d.Id as DId FROM OA_User u,OA_Department d where u.DepartmentID=d.Id group by d.Id").Tables[0];
ExcelClass Ec = new ExcelClass();//创建Excel操作类对象
int Ycount = 1;
Ec.CreateExceFile();//创建Excel文件
Ec.setValue(Ycount, 1, "CENTER", "组织部门");
Ec.setValue(Ycount, 2, "CENTER", "姓名");
Ec.setValue(Ycount, 3, "CENTER", "性别");
Ec.setValue(Ycount, 4, "CENTER", "职位");
Ec.setValue(Ycount, 5, "CENTER", "移动电话");
Ec.setValue(Ycount, 6, "CENTER", "电话");
Ec.setValue(Ycount, 7, "CENTER", "电子邮箱");
Ec.setBorder(1, 1, 1, 1, 50);
Ec.setBorder(1, 2, 2, 2, 20);
Ec.setBorder(1, 5, 5, 5, 20);
Ec.setBorder(1, 6, 6, 6, 20);
Ec.setBorder(1, 7, 7, 7, 20);
for (int i = 0; i < Duser.Rows.Count; i++)
{
Ycount += 1;
Ec.setValue(Ycount, 1, "CENTER", Common.DeleteHtml(Getdept(Duser.Rows[i]["count"], Duser.Rows[i]["DId"])));
DataTable dtuser = GetData(Duser.Rows[i]["DId"]);
for (int k = 0; k < dtuser.Rows.Count; k++)
{
Ec.setValue(Ycount, 2, "CENTER", dtuser.Rows[k]["TrueName"].ToString());
Ec.setValue(Ycount, 3, "CENTER", dtuser.Rows[k]["sex"].ToString());
Ec.setValue(Ycount, 4, "CENTER", dtuser.Rows[k]["PositionId"].ToString());
Ec.setValue(Ycount, 5, "CENTER", dtuser.Rows[k]["Telephone"].ToString());
Ec.setValue(Ycount, 6, "CENTER", dtuser.Rows[k]["Mobile"].ToString());
Ec.setValue(Ycount, 7, "CENTER", dtuser.Rows[k]["Email"].ToString());
Ycount += 1;
}
}
string path = Server.MapPath("Contactfiles\\");
Ec.SaveAs(path+"通讯录.xlsx");
//*******释放Excel资源***********
Ec.ReleaseExcel();
Response.Redirect("Contactfiles/通讯录.xlsx");
}
catch (Exception ex)
{
PageError("导出出错!"+ex.ToString(),"");
}
}
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。
更新日志
- 【雨果唱片】中国管弦乐《鹿回头》WAV
- APM亚流新世代《一起冒险》[FLAC/分轨][106.77MB]
- 崔健《飞狗》律冻文化[WAV+CUE][1.1G]
- 罗志祥《舞状元 (Explicit)》[320K/MP3][66.77MB]
- 尤雅.1997-幽雅精粹2CD【南方】【WAV+CUE】
- 张惠妹.2007-STAR(引进版)【EMI百代】【WAV+CUE】
- 群星.2008-LOVE情歌集VOL.8【正东】【WAV+CUE】
- 罗志祥《舞状元 (Explicit)》[FLAC/分轨][360.76MB]
- Tank《我不伟大,至少我能改变我。》[320K/MP3][160.41MB]
- Tank《我不伟大,至少我能改变我。》[FLAC/分轨][236.89MB]
- CD圣经推荐-夏韶声《谙2》SACD-ISO
- 钟镇涛-《百分百钟镇涛》首批限量版SACD-ISO
- 群星《继续微笑致敬许冠杰》[低速原抓WAV+CUE]
- 潘秀琼.2003-国语难忘金曲珍藏集【皇星全音】【WAV+CUE】
- 林东松.1997-2039玫瑰事件【宝丽金】【WAV+CUE】