asp.net的com方式导出excel
最近做个项目,需要导出excel,要主从表一起导出的,就大致写了一个方法,可能格式方面还是会进行修改,先贴出来方便以后查看
项目引用微软excel的com的dll即可
/// <summary>
/// 功能:导出文件(通过数据源导出,可主从表导出)
/// </summary>
/// <param name="strTitle">文件名字</param>
/// <param name="mainDT">主表数据源</param>
/// <param name="dtParams">从表数据源集合</param>
public static void Export(string strTitle, System.Data.DataTable mainDT, params System.Data.DataTable[] dtParams)
{
GC.Collect();
Application oApp = new Application();
Workbooks oBooks = oApp.Workbooks;
Workbook oBook = oBooks.Add(true);
Worksheet oSheet = (Worksheet)oBook.ActiveSheet;
int _rowIndex = 4;//行索引
int _cellIndex = 1;//列索引
int _maxCellIndex = 1;//最大列索引
int _mainRowIndex = 4;//主表行索引
//绘制标题
oSheet.Cells[2, 2] = strTitle;
//绘制主表数据
foreach (DataColumn col in mainDT.Columns)
{
_cellIndex++;
//设置一行两列
if (_cellIndex > 17)
{
_rowIndex++;
_cellIndex = 2;
}
oSheet.Cells[_rowIndex, _cellIndex] = col.ColumnName+":";
oSheet.get_Range(oSheet.Cells[_rowIndex, _cellIndex], oSheet.Cells[_rowIndex, _cellIndex + 2]).Select();
oSheet.get_Range(oSheet.Cells[_rowIndex, _cellIndex], oSheet.Cells[_rowIndex, _cellIndex + 2]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection;
_cellIndex = _cellIndex + 3;
if (col.DataType == System.Type.GetType("System.DateTime"))// 日期格式
{
oSheet.Cells[_rowIndex, _cellIndex] =Convert.ToDateTime(mainDT.R
相关文档:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string str = "123456789";
//string str1 = Eval("str").ToString ......
前言
ASP.NET MVC作为微软官方的.NET平台下MVC解决方案,自诞生起就吸引了众多.NET平台开发人员的眼球。在经历了漫长Preview后,上个月微软终于发布了其beta版。应该说,通过我亲身实践,我认为这个框架的设计还是相当优秀的,至少从易用性来说,ASP.NET MVC要优于Java平台上的Struts和Str ......
方案一:
/**//// <summary>
/// 名称:IsNumberic
/// 功能:判断输入的是否是数字
/// 参数:string oText:源文本
/// 返回值: bool true:是 false:否
/// </summary>
public bool IsNumberic(string oText)
{
try
{
int var1=Convert.ToInt32 (oText);
return true;
}
catch ......
通常我们都通过下面的代码获得IP:
string ip =System.Web.HttpContext.Current.Request.UserHostAddress;
或 string ip =System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
REMOTE_ADDR 说明:
访问客户端的 IP 地址。
此项信息用户不可以修改。
如果真的 ......
在a.aspx跳转到b.aspx
通过Server.Transfer("b.aspx") 与Response.Redirect("b.aspx")的区别
如果是通过通过Server.Transfer()在a.aspx跳转到b.aspx的,则在b.aspx页面,可以查找到保存在a.aspx页面中的 控件中的值,如果是Response.Redirect(),则得不到到a.aspx页面中控件的值。
如果是通过Server.Transfer("b.aspx" ......