admin 管理员组

文章数量: 1086019


2024年3月10日发(作者:幂函数的定义域范围)

C#导出xls,word,图片及样式问题

public void ExportControl(l source, string DocumentType, string filename)

{

//设置Http的头信息,编码格式

= true;

();

ontent();

eaders();

if (r() == "excel")

{

//Excel

Header("Content-Disposition",

"attachment;filename=" + ode(filename + ".xls", 8));

tType = "application/ms-excel";

}

else if (r() == "word")

{

//Word

Header("Content-Disposition",

"attachment;filename=" + ode(filename + ".doc", 8));

tType = "application/ms-word";

}

t = "UTF-8";

Encoding=8;

tEncoding = 8;

//关闭控件的视图状态

ViewState = false;

//初始化HtmlWriter

Writer writer = new Writer();

xtWriter htmlWriter = new

xtWriter(writer);

Control(htmlWriter);

//输出

(ng());

();

}

public void ExportControl(l source, string DocumentType, string filename)

{

//设置Http的头信息,编码格式

= true;

();

ontent();

eaders();

if (r() == "excel")

{

//Excel

Header("Content-Disposition",

"attachment;filename=" + ode(filename + ".xls", 8));

tType = "application/ms-excel";

}

else if (r() == "word")

{

//Word

Header("Content-Disposition",

"attachment;filename=" + ode(filename + ".doc", 8));

tType = "application/ms-word";

}

t = "UTF-8";

Encoding=8;

tEncoding = 8;

//关闭控件的视图状态

ViewState = false;

//初始化HtmlWriter

Writer writer = new Writer();

xtWriter htmlWriter

xtWriter(writer);

Control(htmlWriter);

//输出

(ng());

();

}

//方法ExportControl(l source, string DocumentType,string filename)

//第一个参数source表示导出的页面或控件名,当为datagrid或dataList控件时,在导出

Excel/word文件时,必须把控件的分页、排序等属性去除并重新绑定,

//第二个参数DocumentType表示导出的文件类型word或excel

//第三个参数filename表示需要导出的文件所取的文件名

1,如果想截取页面中一段,可以:

在页面中要截取的前后分别添加

,然后将writer进行处理:

string pageHtml = ng();

int startIndex = f("

");

int endIndex = dexOf("

");

= new

int lenth = endIndex - startIndex;

pageHtml = ing(startIndex, lenth);

pageHtml = (dexOf("

"));

(ng());

string pageHtml = ng();

int startIndex = f("

");

int endIndex = dexOf("

");

int lenth = endIndex - startIndex;

pageHtml = ing(startIndex, lenth);

pageHtml = (dexOf("