高分分提问,excel 导出,提示CSS丢失问题 可不可以吧CSS 变成文件 上面引用绝对路径。导出的时候引用路径参考 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我的导出代码里面就没CSS样式,错误的样式,是控制HTML页面的 -。- 我哭啊,我的 excel 是用代码画表划成的,里面根本没用到 main.css,样式,,即使,我把main.css删掉,他也会提示,css文件夹里面,别的css错误,我在这个项目遇到这个问题,但是在别的项目上,就没出现,代码直接能用。 -.- 我就郁闷死了,我做别的项目,这个代码直接放上去,就能用,页面也引用了CSS,名字都是一样的,,但是就做这个项目,出这个问题,,郁闷死了 Myxls用这个excel导出组件试试public static void ExportToTable(System.Data.DataTable dtData, string filename) { XlsDocument xls = new XlsDocument(); Worksheet sheet = xls.Workbook.Worksheets.AddNamed(filename);//状态栏标题名称 int rowNum = dtData.Rows.Count; int columnNum = dtData.Columns.Count; int rowIndex = 1; int columnIndex = 0; //生成格式列 ColumnInfo colInfo = new ColumnInfo(xls, sheet); colInfo.ColumnIndexStart = 0; colInfo.ColumnIndexEnd = Convert.ToUInt16(columnNum); colInfo.Width = 20 * 256; sheet.AddColumnInfo(colInfo); //绑定标题 Cell cell = null; foreach (DataColumn dc in dtData.Columns) { columnIndex++; cell = sheet.Cells.AddValueCell(rowIndex, columnIndex, dc.ColumnName); //cell.HorizontalAlignment = HorizontalAlignments.Centered; //cell.Font.Weight = FontWeight.Bold; //cell.PatternColor = Colors.Default30; //cell.RightLineColor = Colors.Black; //cell.RightLineStyle = 1; //cell.BottomLineColor = Colors.Black; //cell.BottomLineStyle = 1; //cell.TopLineColor = Colors.Black; //cell.TopLineStyle = 1; cell.HorizontalAlignment = HorizontalAlignments.Centered; cell.VerticalAlignment = VerticalAlignments.Centered; cell.Pattern = 1; cell.PatternColor = Colors.EgaBlue; cell.UseBorder = true; cell.TopLineStyle = 1; cell.TopLineColor = Colors.Black; cell.BottomLineStyle = 1; cell.BottomLineColor = Colors.Black; cell.LeftLineStyle = 1; cell.LeftLineColor = Colors.Black; cell.RightLineStyle = 1; cell.RightLineColor = Colors.Black; cell.Font.Bold = true; cell.Font.Height = 11 * 20; cell.Font.ColorIndex = 1; } //绑定子项数据 for (int i = 0; i < rowNum; i++) { rowIndex++; columnIndex = 0; for (int j = 0; j < columnNum; j++) { columnIndex++; cell = sheet.Cells.AddValueCell(rowIndex, columnIndex, dtData.Rows[i][j].ToString()); cell.HorizontalAlignment = HorizontalAlignments.Centered; cell.TextWrapRight = true; cell.VerticalAlignment = VerticalAlignments.Top; if (j == 0) { cell.LeftLineColor = Colors.Black; cell.LeftLineStyle = 1; } cell.RightLineColor = Colors.Black; cell.RightLineStyle = 1; cell.BottomLineColor = Colors.Black; cell.BottomLineStyle = 1; } } //导出 xls.FileName = filename; xls.Send(); } -.- 最后找出问题了,,我是迅雷下载下来的,迅雷下下来的是页面,要用IE下载,那样才是EXCEL 如何设计评论比较好? 求教如何提取页面中的css和js! Server Error in '/' Application 水晶報表 难题.将Table表中的内容输入到EXCEL表中. iewebcontrols安装问题 webservice 小问题 昨天去面试了, 还有很多东西不会! web窗体之间是否可以引用? Session的一个非常奇怪的问题!!你们也可能会遇到这样的问题!! 如何将这个arraylist绑定到dropdownlist? ASP.net中登录的方式? gridview显示
用这个excel导出组件试试
public static void ExportToTable(System.Data.DataTable dtData, string filename)
{
XlsDocument xls = new XlsDocument();
Worksheet sheet = xls.Workbook.Worksheets.AddNamed(filename);//状态栏标题名称 int rowNum = dtData.Rows.Count; int columnNum = dtData.Columns.Count; int rowIndex = 1; int columnIndex = 0; //生成格式列
ColumnInfo colInfo = new ColumnInfo(xls, sheet);
colInfo.ColumnIndexStart = 0;
colInfo.ColumnIndexEnd = Convert.ToUInt16(columnNum);
colInfo.Width = 20 * 256; sheet.AddColumnInfo(colInfo); //绑定标题
Cell cell = null;
foreach (DataColumn dc in dtData.Columns)
{
columnIndex++; cell = sheet.Cells.AddValueCell(rowIndex, columnIndex, dc.ColumnName);
//cell.HorizontalAlignment = HorizontalAlignments.Centered;
//cell.Font.Weight = FontWeight.Bold;
//cell.PatternColor = Colors.Default30;
//cell.RightLineColor = Colors.Black;
//cell.RightLineStyle = 1;
//cell.BottomLineColor = Colors.Black;
//cell.BottomLineStyle = 1;
//cell.TopLineColor = Colors.Black;
//cell.TopLineStyle = 1; cell.HorizontalAlignment = HorizontalAlignments.Centered;
cell.VerticalAlignment = VerticalAlignments.Centered;
cell.Pattern = 1;
cell.PatternColor = Colors.EgaBlue;
cell.UseBorder = true;
cell.TopLineStyle = 1;
cell.TopLineColor = Colors.Black;
cell.BottomLineStyle = 1;
cell.BottomLineColor = Colors.Black;
cell.LeftLineStyle = 1;
cell.LeftLineColor = Colors.Black;
cell.RightLineStyle = 1;
cell.RightLineColor = Colors.Black;
cell.Font.Bold = true;
cell.Font.Height = 11 * 20;
cell.Font.ColorIndex = 1; } //绑定子项数据
for (int i = 0; i < rowNum; i++)
{ rowIndex++; columnIndex = 0; for (int j = 0; j < columnNum; j++)
{ columnIndex++; cell = sheet.Cells.AddValueCell(rowIndex, columnIndex, dtData.Rows[i][j].ToString());
cell.HorizontalAlignment = HorizontalAlignments.Centered;
cell.TextWrapRight = true;
cell.VerticalAlignment = VerticalAlignments.Top;
if (j == 0)
{
cell.LeftLineColor = Colors.Black;
cell.LeftLineStyle = 1;
} cell.RightLineColor = Colors.Black;
cell.RightLineStyle = 1;
cell.BottomLineColor = Colors.Black;
cell.BottomLineStyle = 1; } } //导出
xls.FileName = filename;
xls.Send();
}