protected void btnExport_Click(object sender, EventArgs e)
{
DataTable tbBooks = (DataTable)Session["Books"];
if (tbBooks == null)
{
return;
} try
{
Workbook newWorkBook = NewExcel();
Aspose.Cells.Worksheet newSheet = newWorkBook.Worksheets[];
Cells newCells = newSheet.Cells; if (tbBooks != null)
{
for (int i = ; i < tbBooks.Rows.Count; i++)
{ for (int j = ; j < tbBooks.Columns.Count; j++)
{ newCells[i+1, j].PutValue(tbBooks.Rows[i][j].ToString());
}
}
}
newWorkBook.Save("result.xlsx", Aspose.Cells.FileFormatType.Excel97To2003, Aspose.Cells.SaveType.OpenInExcel, Response);
}
catch (Exception ex)
{
MessageBox.Show(this, "导出产品信息库出错,详细错误为:" + ex.Message);
}
} public Workbook NewExcel()
{
DataTable table = (DataTable)Session["Books"];
Workbook newWorkBook = new Workbook();
Aspose.Cells.Worksheet sheet = newWorkBook.Worksheets[];
Cells cells = sheet.Cells; Aspose.Cells.Style style = newWorkBook.Styles[newWorkBook.Styles.Add()];//新增样式
style.HorizontalAlignment = TextAlignmentType.Center;
style.Font.Size = ;
style.Font.Color = System.Drawing.Color.Red;
cells.SetRowHeight(, ); for (int i = ; i < table.Columns.Count; i++)
{
cells[, i].PutValue(table.Columns[i].ColumnName);
cells[, i].SetStyle(style);
cells.SetColumnWidthPixel(i, );
}
return newWorkBook;
}

Asp.net & Aspose.cells 导出的更多相关文章

  1. Aspose.Cells导出Excel(1)

    利用Aspose.Cells导出excel 注意的问题 1.DataTable的处理 2.进行编码,便于中文名文件下载 3.别忘了Aspose.Cells.dll(可以自己在网上搜索) public ...

  2. C#使用Aspose.Cells导出Excel简单实现

    首先,需要添加引用Aspose.Cells.dll,官网下载地址:http://downloads.aspose.com/cells/net 将DataTable导出Xlsx格式的文件下载(网页输出) ...

  3. Aspose.Cells导出Excel(2)

    DataTable dtTitle = ds.Tables[]; DataTable dtDetail = ds.Tables[]; int columns = dtTitle.Columns.Cou ...

  4. C#+Aspose.Cells 导出Excel及设置样式 (Webform/Winform)

    在项目中用到,特此记录下来,Aspose.Cells 不依赖机器装没有装EXCEL都可以导出,很方便.具体可以参考其他 http://www.aspose.com/docs/display/cells ...

  5. Asp.net & Aspose.cells 导入

    Workbook workBook = new Workbook(this.fuFile.FileContent); Aspose.Cells.Worksheet sheet = workBook.W ...

  6. 利用Aspose.Cells导出Datatable数据

    面对一些的格式各样的到处数据的要求,自学了一点 Aspose.Cells中操作Excel知识,如下代码: /// <summary> /// DataTable导出Excel /// &l ...

  7. aspose.cells导出Demo

    /// <summary> /// 导出excel /// </summary> /// <param name="list"></par ...

  8. C# 使用Aspose.Cells 导出Excel

    今天在工作中碰到同事用了一种新型的方式导入excel,在此做个学习记录. 插件:Aspose.Cells 第一步:准备好导出的模板,例子: C#代码: #region 验证数据 if (model = ...

  9. Aspose.Cells 导出 excel

    Aspose.Cells.Workbook book = new Aspose.Cells.Workbook(); Aspose.Cells.Worksheet sheet = book.Worksh ...

随机推荐

  1. Fanvas是一个把swf转为html5 canvas动画的系统

      https://github.com/Tencent/Fanvas   使用方法:     代码: <!DOCTYPE html> <html> <head> ...

  2. iOS开源项目周报0119

    由OpenDigg 出品的iOS开源项目周报第六期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等. Sharaku ...

  3. 十一:image 图片

    属性名 类型 默认值 说明 src String   图片资源地址 mode String 'scaleToFill' 图片裁剪.缩放的模式 binderror HandleEvent   当错误发生 ...

  4. php中的namespace 命名空间

    名字解释: namespace(命名空间),命名空间是从php5.3开始支持的功能.作用主要有两个:1.可以避免类名取得过长.2.当在多个框架配合使用时,同名的类之间不会冲突. 命名空间,看名字就知道 ...

  5. Azure 应用服务中的 API 应用、ASP.NET 和 Swagger 入门

    学习内容: 如何通过 Visual Studio 2015 中的内置工具在 Azure 应用服务中创建和部署 API 应用. 如何使用 Swashbuckle NuGet 包动态生成 Swagger ...

  6. Asp.Net 之Jquery知识点运用

    1.先把要用的body内的代码写好. <div id="ulBox"> <h3>下面的Ulid为"ulList1"</h3> ...

  7. 16、IO (Properties、序列化流、打印流、CommonsIO)

    Properties集合的特点 * A: Properties集合的特点 * a: Properties类介绍 * Properties 类表示了一个持久的属性集.Properties 可保存在流中或 ...

  8. groovy运行程序和类型推断

    在 Java 中,如果要声明一个 String 变量,则必须输入: String value = "Hello World"; 等号右侧的字符已经表明 value 的类型是 Str ...

  9. HDU 2680(最短路)(多个起始点)

    这道题也是死命TLE.. http://acm.hdu.edu.cn/showproblem.php?pid=2680 /* 使用pair代替结构 */ #include <iostream&g ...

  10. 文件下载(Servlet/Struts2)

    文件上传(Servlet/Struts2/SpringMVC)的链接:http://www.cnblogs.com/ghq120/p/8312944.html 文件下载 Servlet实现 目录结构 ...