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. [PY3]——IO——pathlib

    pathlib.Path() from pathlib import Path p=Path("/test2") Path.cwd() print(p.cwd()) /py3 Pa ...

  2. ubuntu上安装R的时候遇到的问题总结

    首先感谢这两篇博客的指导,第一篇是关于报错的总结,第二篇是第一篇中没有提到的错误,也就是我在安装的时候出现的错误. 1.下载R包 (去官网选择一个离你最近的镜像网址,我的是清华提供的镜像下载速度比较快 ...

  3. Java常用的排序算法三

    Merge Sort :归并排序:用递归的思想,分解成单个元素的排序,在归并 代码: import java.util.*; public class MergeSort { public stati ...

  4. C#语法糖($)(?.)(??)

    内插字符串($) 实际上是C# 6.0对string.Format的改进,将字符串文本标识为内插字符串($)根据微软的例子来看: using System; public class Example ...

  5. nodejs文件上传组件multer使用

    多图上传,发送端: var express = require('express') var rp = require('request-promise') var fs = require(&quo ...

  6. golang学习之接口型函数

    先说下使用接口型函数的好处: 1.不必将某个接口函数附在某个type上面,保证了命名随意 2. 可以直接调用函数或者使用该接口,两两不耽误 直接上代码吧: // interface_func proj ...

  7. Spring Boot学习笔记(五)整合mybatis

    pom文件里添加依赖 <!-- 数据库需要的依赖 --> <dependency> <groupId>org.mybatis.spring.boot</gro ...

  8. MVC 手机端页面 使用标签file 图片上传到后台处理

    最近刚做了一个头像上传的功能,使用的是H5 的界面,为了这个功能搞了半天的时间,找了各种插件,有很多自己都不知道怎么使用,后来只是使用了一个标签就搞定了:如果对样式没有太大的要求我感觉使用这个就足够了 ...

  9. Thymeleaf学习记录(4)--$/*/#/@语法

    表达式符号 Thymeleaf对于变量的操作主要有$\*\#三种方式: 变量表达式: ${...},是获取容器上下文变量的值. 选择变量表达式: *{...},获取指定的对象中的变量值.如果是单独的对 ...

  10. WinFrom折线图

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...