淺析C#編程實現(xiàn)動態(tài)生成Word文檔(2)_.Net教程
推薦:淺析Asp.net2.0之自定義控件ImageButton前言 上個星期三開始學自定義控件,做了不少練習�;艘簧衔鐣r間寫了一個imageButton,以前就像寫這個控件,只是不會。 圖片 正文 這個控件模仿winform中的button,可以支持圖片和文字�?梢赃x擇執(zhí)行服務器端程序還是客戶端程序,還有一些簡單的設置。 不足
// 填充表格內(nèi)容
newTable.Cell( 2 , 1 ).Range.Text = " 產(chǎn)品基本信息 " ;
newTable.Cell( 2 , 1 ).Range.Font.Color = Word.WdColor.wdColorDarkBlue; // 設置單元格內(nèi)字體顏色
// 合并單元格
newTable.Cell( 2 , 1 ).Merge(newTable.Cell( 2 , 3 ));
WordApp.Selection.Cells.VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
// 填充表格內(nèi)容
newTable.Cell( 3 , 1 ).Range.Text = " 品牌名稱: " ;
newTable.Cell( 3 , 2 ).Range.Text = BrandName;
// 縱向合并單元格
newTable.Cell( 3 , 3 ).Select(); // 選中一行
object moveUnit = Word.WdUnits.wdLine;
object moveCount = 5 ;
object moveExtend = Word.WdMovementType.wdExtend;
WordApp.Selection.MoveDown( ref moveUnit, ref moveCount, ref moveExtend);
WordApp.Selection.Cells.Merge();
// 插入圖片
string FileName = Picture; // 圖片所在路徑
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; // 圖片高度
// 將圖片設置為四周環(huán)繞型
Word.Shape s = WordDoc.Application.ActiveDocument.InlineShapes[ 1 ].ConvertToShape();
s.WrapFormat.Type = Word.WdWrapType.wdWrapSquare;
newTable.Cell( 12 , 1 ).Range.Text = " 產(chǎn)品特殊屬性 " ;
newTable.Cell( 12 , 1 ).Merge(newTable.Cell( 12 , 3 ));
// 在表格中增加行
WordDoc.Content.Tables[ 1 ].Rows.Add( ref Nothing);
WordDoc.Paragraphs.Last.Range.Text = " 文檔創(chuàng)建時間: " + DateTime.Now.ToString(); // “落款”
WordDoc.Paragraphs.Last.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;
// 文件保存
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);
message = name + " 文檔生成成功,以保存到C:CNSI下 " ;
}
catch
... {
message = " 文件導出異常! " ;
}
return message;
}
分享:淺談.net程序員,該不該學IL?最近一直在思考一個問題,那就是.net程序員的發(fā)展,應該往上走還是往下走的事情。所謂往上走,我的理解是朝著系統(tǒng)架構(gòu)方向發(fā)展,從原來的編碼工作轉(zhuǎn)向架構(gòu)、設計、分析等等工作。 而往下走,是研究.net底層原理和實現(xiàn),可能大部分就是對IL和CLR的研究。 最近
- asp.net如何得到GRIDVIEW中某行某列值的方法
- .net SMTP發(fā)送Email實例(可帶附件)
- js實現(xiàn)廣告漂浮效果的小例子
- asp.net Repeater 數(shù)據(jù)綁定的具體實現(xiàn)
- Asp.Net 無刷新文件上傳并顯示進度條的實現(xiàn)方法及思路
- Asp.net獲取客戶端IP常見代碼存在的偽造IP問題探討
- VS2010 水晶報表的使用方法
- ASP.NET中操作SQL數(shù)據(jù)庫(連接字符串的配置及獲取)
- asp.net頁面?zhèn)髦禍y試實例代碼
- DataGridView - DataGridViewCheckBoxCell的使用介紹
- asp.net中javascript的引用(直接引入和間接引入)
- 三層+存儲過程實現(xiàn)分頁示例代碼
- 相關(guān)鏈接:
- 教程說明:
.Net教程-淺析C#編程實現(xiàn)動態(tài)生成Word文檔(2)
。