導航:首頁 > 文字圖片 > aspnet圖片導出word

aspnet圖片導出word

發布時間:2022-05-01 19:55:47

『壹』 asp.net實現將數據輸出到word

public void Download()
{
Random rd = new Random();
string fileName = DateTime.Now.ToString("yyyyMMddhhmm") + rd.Next() + ".doc";
//存儲路徑
string path = Server.MapPath(fileName);
//創建字元輸出流
StreamWriter sw = new StreamWriter(path, true, System.Text.UnicodeEncoding.UTF8);

//需要導出的內容
string str = "<html><head><title>無標題文檔</title></head><body>這里放從資料庫導出的word文檔內容</body></html>";

//寫入
sw.Write(str);
sw.Close();
Response.Clear();
Response.Buffer = true;
this.EnableViewState = false;
Response.Charset = "utf-8";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.ContentType = "application/octet-stream";
Response.WriteFile(path);
Response.Flush();
Response.Close();
Response.End();
}

標准word文檔的格式微軟暫未公布,由此我們可將需要導出的內容轉為標准HTML文件儲存,後綴名為.doc

也可以將要導出內容轉為標准XML格式存儲,改後綴為.doc

具體格式隨意新建個word文檔,輸入內容,另存為.XML可見

另外一種導出方式為word導出標准格式,伺服器需要安裝Microsoft Office word,需要預先設置好一個word文檔並在要插入內容的地方設置書簽做為模版,導出word文檔時需要先遍歷模版文件中的所有書簽,然後給書簽賦值就能實現導出數據了

還有不懂的可以直接網路HI我

『貳』 .net頁面導出word不顯示圖片

用普通的保存成word的代碼是不能實現的,我曾經是用c#引用Microsoft.Office.Interop.Word來創建word,才能在其中添加圖片,不知道對你有沒有用:

Object Nothing = System.Reflection.Missing.Value;
Directory.CreateDirectory("C:/CNSI"); //創建文件所在目錄
string name = "CNSI_" + DateTime.Now.ToShortDateString()+ ".doc";
object filename = "C://CNSI//" + name; //文件保存路徑
//創建Word文檔
Application WordApp = new ApplicationClass();
Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);

//插入圖片
string FileName = Server.MapPath("~/http_imgloadCADN55WM.jpg");//圖片所在路徑
object LinkToFile = false;
object SaveWithDocument = true;
object Anchor = WordDoc.Application.Selection.Range;
WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref Anchor);
// WordDoc.Application.ActiveDocument.InlineShapes[1].Width = 100f;//圖片寬度
// WordDoc.Application.ActiveDocument.InlineShapes[1].Height = 100f;//圖片高度
//文件保存
WordDoc.SaveAs(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
WordApp.Quit(ref Nothing, ref Nothing, ref Nothing);

『叄』 ASP.NET 頁面內容導出word,圖片不顯示的問題。

首先要使用圖片的絕對路徑,如果還是沒有看到圖片,說明word沒有internet鏈接,其實用html內容直接轉word有這種問題是一定的。
如果是企業級的系統,是有必要購買一些好的html轉word的第三方工具。不能只是html直接生成word文檔,歸根結底生成後的word文檔其實還是html格式,只不過換了個後綴名而已。

『肆』 asp.net MVC3.0中 如何把數據導出到WORD中

先用word建立好文檔,然後存一個html,然後mvc把這個html中需要動態生成的部分用程序替換掉,輸出文件頭寫成word,文件名.doc就行了

『伍』 asp.net web頁面導出word

asp.net
,web頁面中的查詢數據導出Word,實現思路
一:需要把自己查詢後的結構組裝成一張數據集,如DataTable或DataSet..
二:定義需要導出的欄位與資料庫所創建列對應
三:確定導出那張表,傳如:表名
希望對你有用!

『陸』 asp.net(C#) 導出到word excel [100分]

這個分我拿定了。和我以前做的一個功能很像。網站數據,轉換成 淘寶數據包文件 (csv 或者 excel) private void bind_db()
{
DataSet ds = bus.GetGoodData(txt_start.Text,txt_end.Text);

this.Results.Columns.Add("g_name",typeof(string)); //寶貝名稱
this.Results.Columns.Add("g_type",typeof(string)); //寶貝類目【50000671】
this.Results.Columns.Add("s_type",typeof(string)); //店鋪類目【19165853】
this.Results.Columns.Add("g_old",typeof(string)); //新舊程度【5】
this.Results.Columns.Add("g_province",typeof(string)); //省【海外】
this.Results.Columns.Add("g_city",typeof(string)); //市【海外】
this.Results.Columns.Add("g_sell",typeof(string)); //出售方式【b】
this.Results.Columns.Add("g_price",typeof(string)); //寶貝價格【】
this.Results.Columns.Add("g_uprice",typeof(string)); //加價幅度【0】
this.Results.Columns.Add("g_count",typeof(string)); //寶貝數量【10000】
this.Results.Columns.Add("g_date",typeof(string)); //有效期【14】
this.Results.Columns.Add("g_posstake",typeof(string)); //運費承擔【1】
this.Results.Columns.Add("g_poss",typeof(string)); //平郵【10】
this.Results.Columns.Add("g_ems",typeof(string)); //EMS【25】
this.Results.Columns.Add("g_express",typeof(string)); //快遞【10】
this.Results.Columns.Add("g_pay",typeof(string)); //付款方式【0】
this.Results.Columns.Add("g_payment",typeof(string)); //支付寶【1】
this.Results.Columns.Add("g_receipt",typeof(string)); //發票【0】
this.Results.Columns.Add("g_guarantee",typeof(string)); //保修【0】
this.Results.Columns.Add("g_again",typeof(string)); //自動重發【1】
this.Results.Columns.Add("g_deport",typeof(string)); //放入倉庫【0】
this.Results.Columns.Add("g_recommend",typeof(string)); //櫥窗推薦【0】
this.Results.Columns.Add("g_pubtime",typeof(string)); //發布時間【1980-1-1 0:00:00】
this.Results.Columns.Add("g_story",typeof(string)); //心情故事【每天有個好心情!】
this.Results.Columns.Add("g_info",typeof(string)); //寶貝描述【】
this.Results.Columns.Add("g_img",typeof(string)); //寶貝圖片【】
//20661:29444;20662:29914;20663:29448;20664:29920;20665:29454;20666:29937;20666:29457;20666:29938;20509:28314;20509:28315;20509:28383;20510:28320;20511:28386;
this.Results.Columns.Add("g_property",typeof(string)); //寶貝屬性【】
this.Results.Columns.Add("g_team",typeof(string)); //團購價【0】
this.Results.Columns.Add("g_teamnum",typeof(string)); //最小團購件數【10】
this.Results.Columns.Add("g_posstype",typeof(string)); //郵費模版ID【10】
this.Results.Columns.Add("g_member",typeof(string)); //會員打折【0】
this.Results.Columns.Add("g_updatetime",typeof(string)); //修改時間【】
this.Results.Columns.Add("g_state",typeof(string)); //上傳狀態【100】
this.Results.Columns.Add("g_imgstate",typeof(string)); //圖片狀態【0】 for(int n=0;n<ds.Tables[0].Rows.Count;n++)
{
DataRow newrow = Results.NewRow();
newrow["g_name"] = ds.Tables[0].Rows[n]["g_id"].ToString() + ds.Tables[0].Rows[n]["g_name"].ToString();
newrow["g_type"] = "50000671";
newrow["s_type"] = "19165853";
newrow["g_old"] = "5";
newrow["g_province"] = "上海";
newrow["g_city"] = "上海";
newrow["g_sell"] = "b";
newrow["g_price"] = ds.Tables[0].Rows[n]["g_marketprice"].ToString();
newrow["g_uprice"] = "0";
newrow["g_count"] = ds.Tables[0].Rows[n]["g_count"].ToString();
newrow["g_date"] = "14";
newrow["g_posstake"] = "1";
newrow["g_poss"] = "10";
newrow["g_ems"] = "25";
newrow["g_express"] = "10";
newrow["g_pay"] = "0";
newrow["g_payment"] = "1";
newrow["g_receipt"] = "0";
newrow["g_guarantee"] = "0";
newrow["g_again"] = "1";
newrow["g_deport"] = "0";
newrow["g_recommend"] = "0";
newrow["g_pubtime"] = ds.Tables[0].Rows[n]["g_publishtime"].ToString();
newrow["g_story"] = "每天有個好心情!";// string Ginfo = ds.Tables[0].Rows[n]["g_info"].ToString();
// Ginfo = System.Text.RegularExpressions.Regex.Replace(Ginfo,"/<(font|\\/font).*?(?!align).*?>/ig","");
// // Ginfo = System.Text.RegularExpressions.Regex.Replace(Ginfo,"<[^>]+>","");
// newrow["g_info"] = Ginfo;
// //newrow["g_info"] = System.Text.RegularExpressions.Regex.Replace(Ginfo,"<[^>]+>","");
newrow["g_info"] = ds.Tables[0].Rows[n]["g_info"].ToString().Replace("<","<").Replace(">",">");
//Info有字數限制。。。。。。。。。。。。。
newrow["g_img"] = @"F:\SootaoData\" + ds.Tables[0].Rows[n]["g_img"].ToString() + ".jpg";
newrow["g_property"] = "20661:29444;20662:29914;20663:29448;20664:29920;20665:29454;20666:29937;20666:29457;20666:29938;20509:28314;20509:28315;20509:28383;20510:28320;20511:28386";
newrow["g_team"] = "0";
newrow["g_teamnum"] = "10";
newrow["g_posstype"] = "10";
newrow["g_member"] = "0";
newrow["g_updatetime"] = "";
newrow["g_state"] = "100";
newrow["g_imgstate"] = "0"; Results.Rows.Add(newrow); PagedDataSource ps = new PagedDataSource();
ps.DataSource = Results.DefaultView;
dg_data.DataSource = ps;
dg_data.DataBind();
//fileRead.Close();
}
}

『柒』 asp.net頁面導出word後樣式問題

要達到這種效果,把生成的簡歷的內容都放在一個table里,然後用JS導出。
給你個例子參考。表格中可以包括圖片等元素,都可以正常導出。
<table width="100%" border="1" id = "PrintA">
<tr>
<td>dfsdfds</td>
<td>&dsfds</td>
<td>&sdf;</td>
<td><img src="1.jpg"/></td>
</tr>
<tr>
<td>dsf</td>
<td>dsfds</td>
<td>fsdfdsfdsf</td>
<td>dsfs</td>
</tr>
<tr>
<td>dsfds</td>
<td>dsf</td>
<td>dsfd</td>
<td>sfds</td>
</tr>
<tr>
<td></td>
<td>sdf</td>
<td>fdsf</td>
<td></td>
</tr>
</table>
<input type="button" onclick="javascript:AllAreaWord();" value="導出頁面指定區域內容到Word">
<script type="text/javascript" language="javascript">
//指定頁面區域內容導入Word
function AllAreaWord()
{
var oWD = new ActiveXObject("Word.Application");
var oDC = oWD.Documents.Add("",0,1);
var oRange =oDC.Range(0,1);
var sel = document.body.createTextRange();
sel.moveToElementText(PrintA);
sel.select();
sel.execCommand("Copy");
oRange.Paste();
oWD.Application.Visible = true;
//window.close();
oWD.ActiveWindow.ActivePane.View.Type=3
oWD.Application.close;
}
</SCRIPT>
</body></html>

『捌』 .net如何批量導出word

在列表頁面導出所有明細數據?
1、保證在列表頁面能夠獲取到所有的明細數據
2、添加一個導出按鈕,在按鈕的事件中寫導出的代碼
一般導出需要三個步驟①打開與OFFICE的連接②創建一個操作Word的對象③在這個對象中填充你的數據
如果是要求導出多個Word的話,將步驟②放在一個循環中就可以了。

『玖』 asp.net 導出word圖片顯示問題

注意:我的代碼。
<div>
<asp:GridView ID="GridView1" runat="server"
ShowFooter="True">
</asp:GridView>
<asp:HiddenField ID="HiddenField1" runat="server" />
</div>

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

protected void Button1_Click(object sender, EventArgs e)
{
foreach (Control c in form1.Controls)
{
HiddenField hf = c as HiddenField;
if (hf != null)
{
hf.Visible = false;
}
}
Response.AddHeader("content-disposition", "inline; filename=1.doc");
Response.ContentType = "application/msword";
}

『拾』 asp.net導出word自定義格式

循環(for循環或者foreach)讀取數據再插入word,首先在頂端寫入會議名稱和會議時間,count為15的整倍數時,接著在後面生成分隔符(分頁符)

閱讀全文

與aspnet圖片導出word相關的資料

熱點內容
老北京網鞋價格及圖片 瀏覽:209
動漫戰友圖片 瀏覽:886
兒童連心發型圖片 瀏覽:15
男生圖片帥氣高清頭像圖片 瀏覽:503
暖心的圖片唯美的女孩圖片 瀏覽:132
美女的小便真圖片大全 瀏覽:179
如何製作圖片電子書 瀏覽:632
手工水果擺盤簡單圖片 瀏覽:165
列印圖片怎麼居中 瀏覽:644
碎花點可愛圖片壁紙 瀏覽:783
中國紅包文字圖片大全 瀏覽:871
如何能看圖片上模糊的字 瀏覽:157
男生qq拍照圖片 瀏覽:639
李曉璐發型圖片 瀏覽:145
女孩閨蜜頭像圖片 瀏覽:986
可愛小斗圖圖片 瀏覽:502
用ps怎麼裁剪圖片 瀏覽:51
小林變成男生的圖片 瀏覽:508
男生女生頭部的簡筆畫圖片 瀏覽:712
頭像孩子圖片大全可愛 瀏覽:268