国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

將控件中的數據輸出保存到本地excel或word中,同時保存圖片到本地(c#)

2024-07-21 02:25:30
字體:
來源:轉載
供稿:網友
//把table控件中的數據保存到excel或word
public void save(system.web.ui.control source, documenttype type)

{
response.clear();
response.buffer= true;

//設置http的頭信息,編碼格式
if (type == documenttype.excel)
{
//excel
response.appendheader("content-disposition","attachment;filename=result.xls");
response.contenttype = "application/ms-excel";
}
else if (type == documenttype.word)
{
//word
response.appendheader("content-disposition","attachment;filename=result.doc");
response.contenttype = "application/ms-word";
}

//設置編碼
response.charset="gb2312";
response.contentencoding=system.text.encoding.getencoding("gb2312");

//關閉控件的視圖狀態
source.enableviewstate =false;

//初始化htmlwriter
system.io.stringwriter writer = new system.io.stringwriter() ;
system.web.ui.htmltextwriter htmlwriter = new system.web.ui.htmltextwriter(writer);
source.rendercontrol(htmlwriter);

//輸出
response.write(writer.tostring());

response.end();
}


//以下是保存圖片
public void savepic()
{
string path = server.mappath(".") + @"/images/chart.jpeg";
filestream file = file.openread(path);
byte[] content = new byte[file.length];
file.read(content,0,content.length);
file.close();

response.clear();
response.appendheader("content-disposition","attachment;filename=chart.jpeg");
response.contenttype = "image/jpeg";//設置http的頭信息
response.binarywrite(content);//輸出

response.end();
}

不過圖片保存完后,頁面上的dropdownlist的select事件不能促發,不曉得是什么緣故,而頁面上的button事件卻可以激發事件,不知道大家有沒有出現過這種問題?可以討論一下,還是我保存圖片的過程有問題?

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 昌黎县| 金溪县| 榆社县| 江达县| 萝北县| 南宁市| 嵊州市| 鹤庆县| 张家川| 冷水江市| 调兵山市| 湖北省| 上杭县| 无为县| 基隆市| 巴塘县| 兴和县| 维西| 禄丰县| 珲春市| 阜城县| 东山县| 南川市| 高平市| 宜春市| 定陶县| 曲靖市| 虎林市| 龙口市| 宁远县| 岑溪市| 醴陵市| 什邡市| 北流市| 梨树县| 台湾省| 克拉玛依市| 烟台市| 会同县| 玉环县| 资源县|