c#后台如何导出excel到本地_C#后台导出Excel
using System;
using System.Data;
using System.Drawing;
using System.IO;
using System.Web;
protected void Derived_Click(object sender, EventArgs e)
{
//定義獲取數據的表明
string customFormName = "客戶資料";
string sqlQuery = "";
DataTable dt = null;
//讀出你的數據表
string filter = GetFilter();
sqlQuery = string.Format("Select 1,2,3,4,5,6,7,8,9,0 From customer_list_new_view Where {0} {1} And rownum<=500 ", tabStrip.SelectedTab.Value, filter);
dt =GetDataTable(Database, sqlQuery);
//修改標題(dt的表頭對應dt里面的1-10個字段,如果不替換導出時將顯示你原本的字段名稱)
string[] columns = new string[] { "客戶昵稱", "真實姓名", "客戶來源", "客戶類型", "客戶級別", "手機", "郵箱", "歸屬門店", "會員卡", "折扣"};
for (int i = 0; i < columns.Length; i++)
{
dt.Columns[i].Caption = columns[i];
}
//創建文檔
Workbook wb = new Workbook();
wb.Worksheets.Clear();
wb.Worksheets.Add(SheetType.Worksheet);
Worksheet ws = wb.Worksheets[0];
http://www.doczj.com/doc/42687d936bec0975f465e234.html = customFormName;
//文檔中寫入數據
//ws.Cells.Merge(0, 0, 1, 35); //合并單元格(起始行,起始列,行偏移量,列偏移量)
//ws.AutoFitRow(0, 0, 0); //指定行設置為自適應行寬(行標(從開始),開始列(從開始),結束列(從開始))
ws.Cells.ImportDataTable(dt, true, 0, 0, dt.Rows.Count, dt.Columns.Count);
for (int i = 1; i < 2 + dt.Rows.Count; i++)
{
for (int j = 0; j < dt.Columns.Count; j++)
{
ws.Cells[i, j].Style.HorizontalAlignment = TextAlignmentType.Center;
//設置表格邊框
Aspose.Cells.Range range = ws.Cells.CreateRange(i, j, 1, 1);
range.SetOutlineBorder(Aspose.Cells.BorderType.BottomBorder,
總結
以上是生活随笔為你收集整理的c#后台如何导出excel到本地_C#后台导出Excel的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: gdb条件断点的值一定会断吗_GDB:如
- 下一篇: 基于栅格地图的粒子群算法_基于GMapp