导出Excel模板如何定义单元格格式
金蝶云社区-Meliodas
Meliodas
0人赞赏了该文章 2,002次浏览 未经作者许可,禁止转载编辑于2017年05月24日 11:25:44

这边客户要求导出付款到模板到EXCEL中 付款 农商的批量付款模板要求表头默认加粗 导出代码写好了。。。但是加粗功能不知道该怎么加。。。请老师指导下 源码如下

private void NSExportExcel()
{
DataSet dataSet = new DataSet();
DataTable dt = dataSet.Tables.Add();

String[] A = { "收款人账号", "收款人户名", "收款人开户行", "联行号","币种(CNY:人民币)","金额","收款人类型(0: 行内;1:跨行)","转账用途"};

dt.Columns.Add("收款人账号", typeof(string));//添加列
dt.Columns.Add("收款人户名", typeof(string));
dt.Columns.Add("收款人开户行", typeof(string));
dt.Columns.Add("联行号", typeof(string));
dt.Columns.Add("币种(CNY:人民币)", typeof(string));
dt.Columns.Add("金额", typeof(string));
dt.Columns.Add("收款人类型(0: 行内;1:跨行)", typeof(string));
dt.Columns.Add("转账用途", typeof(string));

String[] pkValues2 = (from p in this.ListView.SelectedRowsInfo select p.PrimaryKeyValue).ToArray();
if (pkValues2.Length != 0)
{
int pkValues = (from p in this.ListView.SelectedRowsInfo select p.PrimaryKeyValue).Count();
if (pkValues != 0)
{
String[,] arr = new String[pkValues + 1, 19];

for (int i = 0; i < A.Length; i++)
{
arr[0, i] = A[i];
}

for (int data = 1; data <= pkValues; data++)
{
String SQL = "/*dialect*/ select FOPPOSITEBANKACCOUNT as 收款帐号,FOPPOSITECCOUNTNAME as 收款账号名称,FOPPOSITEBANKNAME as 收款账号开户行, FCNAP 联行号,'CNY' as 币种,FP as 金额, "
+ " case when FOPPOSITEBANKNAME like '%农商%' then '0' else '1' end 收款人类型,FBILLNO as 转账用途 "
+ " from (SELECT CONVERT(decimal(23,2),FREALPAYAMOUNTFOR) AS FP ,* FROM T_AP_PAYBILL ) a "
+ " left join T_AP_PAYBILLENTRY_B b on a.FID = b.FID"
+ " left join T_AP_PAYBILLentry c on b.FID =c.FID"
+ " left join (SELECT B.FNAME AS BFNAME,C.FNAME AS ZZ ,A.* FROM T_CN_BANKACNT A LEFT JOIN T_BD_BANK_L B ON A.FBANKID=B.FBANKID Left join T_ORG_ORGANIZATIONS_L C on a.FUseOrgId=C.FORGID) d on c.FACCOUNTID=d.FBANKACNTID"
+ " LEFT JOIN T_CN_RECPAYPURPOSE_L H ON C.FPURPOSEID=H.FID "
+ " WHERE a.FID='" + pkValues2[data - 1].ToString() + "'";

var materialIds = DBServiceHelper.ExecuteDynamicObject(this.Context, SQL);
{
foreach (var dataRow in materialIds)
{
arr[data, 0] = Convert.ToString(dataRow["收款帐号"]);
arr[data, 1] = Convert.ToString(dataRow["收款账号名称"]);
arr[data, 2] = Convert.ToString(dataRow["收款账号开户行"]);
arr[data, 3] = Convert.ToString(dataRow["联行号"]);
arr[data, 4] = Convert.ToString(dataRow["币种"]);
arr[data, 5] = Convert.ToString(dataRow["金额"]);
arr[data, 6] = Convert.ToString(dataRow["收款人类型"]);
arr[data, 7] = Convert.ToString(dataRow["转账用途"]);
}
}
}

for (int i = 0; i <= pkValues; i++)
{
DataRow dr = dt.NewRow();
dr["收款人账号"] = arr[i, 0];
dr["收款人户名"] = arr[i, 1];
dr["收款人开户行"] = arr[i, 2];
dr["联行号"] = arr[i, 3];
dr["币种(CNY:人民币)"] = arr[i, 4];
dr["金额"] = arr[i, 5];
dr["收款人类型(0: 行内;1:跨行)"] = arr[i, 6];
dr["转账用途"] = arr[i, 7];
dt.Rows.Add(dr);
}

ExcelOperation helper = new ExcelOperation();
helper.BeginExport();
helper.ExportToFile(dataSet);

string fileName = string.Format("{0}_{1}", "NC_c_", //this.Model.BusinessInfo.GetForm().Name,
DateTime.Now.ToString("yyyyMMddHHmm"));

string[] IllegalStrs = new string[] { "/", "\\" };
foreach (var str in IllegalStrs)
{
fileName = fileName.Replace(str, "");
}

fileName = PathUtils.GetValidFileName(fileName);
string _FilePath = PathUtils.GetPhysicalPath(KeyConst.TEMPFILEPATH, fileName);
string _OutServicePath = PathUtils.GetServerPath(KeyConst.TEMPFILEPATH, fileName);
_FilePath += ".xlsx";
_OutServicePath += ".xlsx";
helper.EndExport(_FilePath, SaveFileType.XLSX);

//下载文件
DynamicFormShowParameter param = new DynamicFormShowParameter();
param.FormId = "BOS_FileDownLoad";
param.OpenStyle.ShowType = ShowType.Modal;
param.CustomParams.Add("IsExportData", "true");
param.CustomParams.Add("url", _OutServicePath);
this.View.ShowForm(param);
}
}
else
{
this.View.ShowErrMessage("请至少选择一行数据!");
}
}

要求格式是这样的


现在格式是这样的