解决方案 »
- VS2010做WEB开发时,启动后在解决方案下会有一个"脚本文档" 如图↓ 如何禁用此功能呢?有些影响开发速度~ 分不多,不好意思!
- 求个算法?
- 各位远程管理服务器和文件上传下载都是用什么软件的?
- 请教一个ajax.net的问题(按钮提交)
- 服务器按钮问题
- 验证正数该怎么写
- 求助
- 在线等,<globalization requestEncoding="gb2312" responseEncoding="gb2312" fileEncoding="gb2312" />的问题
- 怎么样获取datagrid1中的页眉(asp.net(vb))
- access中日期/时间型字段如何更新?
- 前台充值成功如何在后台网站播放提示音乐
- select option 选中值之后,刷新页面,怎么显示上次选定的值
对于Excel的可选方案:简单无格式少数据量用OLEDB读写即可,其他情况建议用NOPI组件。
1.服务器上必须安装office,而且必须跟使用的dll版本一致
2.32位64位必须一致
3.需要注册DCOM
4.需要给权限
5.读取写入其实是利用excel进程打开新建,有时会有死进程,在单机版还可以杀死无窗口进程,在服务器多用户登陆多线程执行,根本没法处理
{
Row headerRow = sheet.CreateRow(0);
headerRow.HeightInPoints = 25;
headerRow.CreateCell(0).SetCellValue(strHeaderText); CellStyle headStyle = workbook.CreateCellStyle(); //设置单元格边框 ,无法实现
headStyle.BorderBottom = CellBorderType.THIN;
headStyle.BorderLeft = CellBorderType.THIN;
headStyle.BorderRight = CellBorderType.THIN;
headStyle.BorderTop = CellBorderType.THIN;
headStyle.Alignment = HorizontalAlignment.CENTER;
Font font = workbook.CreateFont();
font.FontHeightInPoints = 20;
font.Boldweight = 700;
headStyle.SetFont(font); /// <summary>
/// 用于Web导出
/// </summary>
/// <param name="dtSource">源DataTable</param>
/// <param name="strHeaderText">表头文本</param>
/// <param name="strFileName">文件名</param>
/// <Author> </Author>
public static void ExportByWeb(DataTable dtSource, string strHeaderText, string strFileName)
{ HttpContext curContext = HttpContext.Current; // 设置编码和附件格式
curContext.Response.ContentType = "application/vnd.ms-excel";
curContext.Response.ContentEncoding = Encoding.UTF8;
curContext.Response.Charset = "";
curContext.Response.AppendHeader("Content-Disposition",
"attachment;filename=" + HttpUtility.UrlEncode(strFileName, Encoding.UTF8)); curContext.Response.BinaryWrite(Export(dtSource, strHeaderText).GetBuffer());
curContext.Response.End(); }
你现在定义了headStyle但是没把他赋值给cell.Style啊,那不是白定义 了2.现在本来就是生成在服务器,然后用浏览器下载的
如何支持迅雷下载是另一个问题,跟这个无关
留下句柄,不要创建完就不要了,那你还怎么给它设置属性另外,我给你的链接你是一点都没看啊
别人给你代码你不看,还在那问,其实都不太想继续搭理你了
{ Row headerRow = sheet.CreateRow(0);
headerRow.HeightInPoints = 25;
CellStyle headStyle = workbook.CreateCellStyle();
headStyle.Alignment = HorizontalAlignment.CENTER; Font font = workbook.CreateFont();
font.FontHeightInPoints = 20;
font.Boldweight = 700;
headStyle.SetFont(font); //设置单元格边框 在此无效
headStyle.BorderBottom = CellBorderType.THIN;
headStyle.BorderLeft = CellBorderType.THIN;
headStyle.BorderRight = CellBorderType.THIN;
headStyle.BorderTop = CellBorderType.THIN;
headerRow.CreateCell(0).SetCellValue(strHeaderText);
headerRow.GetCell(0).CellStyle = headStyle;
Region rg = new Region(0, 0, 0, dtSource.Columns.Count - 1);
sheet.AddMergedRegion(Region.ConvertToCellRangeAddress(rg));
//headerRow.Dispose();
}
#endregion
#region 列头及样式
{
Row headerRow = sheet.CreateRow(1);
CellStyle headStyle = workbook.CreateCellStyle();
headStyle.Alignment = HorizontalAlignment.CENTER;
Font font = workbook.CreateFont();
font.FontHeightInPoints = 10;
font.Boldweight = 700;
headStyle.SetFont(font); //设置单元格边框
headStyle.BorderBottom = CellBorderType.THIN;
headStyle.BorderLeft = CellBorderType.THIN;
headStyle.BorderRight = CellBorderType.THIN;
headStyle.BorderTop = CellBorderType.THIN;
foreach (DataColumn column in dtSource.Columns)
{
headerRow.CreateCell(column.Ordinal).SetCellValue(column.ColumnName);
headerRow.GetCell(column.Ordinal).CellStyle = headStyle;
//列头及样式设置列宽
sheet.SetColumnWidth(column.Ordinal, (arrColWidth[column.Ordinal] + 1) * 256);
}
//headerRow.Dispose();
}
#endregion
你就不敢定义个变量
ICell cell=headerRow.CreateCell()
然后直接给cell.Style赋值
非要先create,再get
DEMO你真的看了吗
NOPI没有试过!!