excel模板设置
私车公用单 | |||||||||
申请信息 | |||||||||
申请单号: | $header.ORDER_NO | 申请日期: | $header.CREATE_TIME | $auotheight | |||||
申请部门: | $header.APPLY_DEPT | 申请人: | $header.APPLY_USER | $auotheight | |||||
项目: | $header.PROJECT_RD_NAME | 客户: | $header.CUST_NAME | $auotheight | |||||
出差单号: | $header.BST_NO | $auotheight | |||||||
用车信息 | |||||||||
派车日期 | 使用人 | 车辆类型车牌 | 用车事由 | 出发地 | 目的地 | 行驶路线 | |||
$list.detail ASSIGN_DATE | $CAR_OWNER | $CAR_NUMBER | $REASON | $START_POINT | $END_POINT | $listend.ROUTE_NOTES | $auotheight | ||
签核信息 | |||||||||
序号 | 日期 | 步骤 | 签核部门 | 签核人 | 结果 | 签核意见 | |||
$list.ad SEQ | $EVENT_TIME | $AUDIT_DESC | $DEPT_NAME | $USER_NAME | $AUDIT_RESULT | $listend.AUDIT_MARK | $auotheight | ||
使用方式:
1.首先查询数据,DataSet ds=GetData(orderno);
2.然后调用,支持一个sheet模板导出多个数据sheet,多个sheet模板导出多个数据sheet
string fpath = "私车公用单.xls";
ExcelHelper.Helper excel = new ExcelHelper.Helper();
NPOI241.SS.UserModel.IWorkbook workbook = excel.Export(fpath, (book) =>
{
List<ExcelHelper.Helper.ExcelHelperSheetInfo> sinfo = new List<ExcelHelper.Helper.ExcelHelperSheetInfo>();
ExcelHelper.Helper.ExcelHelperSheetInfo info = new ExcelHelper.Helper.ExcelHelperSheetInfo();
sinfo.Add(info);
info.ModelSheet = book.GetSheetAt(0);
info.NewSheetData = new List<object>();
Hashtable ht = new Hashtable();
info.NewSheetData.Add( ht);
ht.Add("header", ds.Tables[0].Rows[0]);
ht.Add("detail", ds.Tables[1].DefaultView);
ht.Add("ad",ds.Tables[2].DefaultView);
return sinfo;
}, (book, sheet, info) => {
sheet.ProtectSheet("123456");
});
using Newtonsoft.Json;
using NPOI241.HSSF.Record;
using NPOI241.HSSF.UserModel;
using NPOI241.HSSF.Util;
using NPOI241.SS.UserModel;
using NPOI241.SS.UserModel.Charts;
using NPOI241.SS.Util;
using NPOI241.XSSF.UserModel;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Web;
namespace WebPortal.Common.ExcelHelper
{
public struct SimpleCell
{
/// <summary>
/// 文本
/// </summary>
public string T { get; set; }
/// <summary>
/// colspan
/// </summary>
public int C { get; set; }
/// <summary>
/// rowspan
/// </summary>
public int R { get; set; }
/// <summary>
/// 样式 文本颜色,背景颜色,字体是否加粗,对齐,宽度
/// </summary>
public string S { get; set; }
/// <summary>
/// 备注
/// </summary>
public string RK { get; set; }
}
public struct SimpleChart
{
/// <summary>
/// 标题
/// </summary>
public string Title { get; set; }
/// <summary>
/// 类型 chart类型 bar和line
/// </summary>
public string Type { get; set; }
/// <summary>
/// 数据起始单元格
/// </summary>
public int Col1 { get; set; }
/// <summary>
/// 数据起始行
/// </summary>
public int Row1 { get; set; }
/// <summary>
/// 数据结束单元格
/// </summary>
public int Col2 { get; set; }
/// <summary>
/// 数据结束行
/// </summary>
public int Row2 { get; set; }
/// <summary>
/// 是否应用右边Y轴,默认左边Y轴
/// </summary>
public bool RightY { get; set; }
}
public class SimpleTable
{
/// <summary>
/// 行数据如
/// </summary>
public List<List<SimpleCell>> Rows { get; set; }
/// <summary>
///